1
1

More than 3 years have passed since last update.

Jenkins+Kubernetesで動的に並列ジョブを定義したい場合

Posted at
jenkinspipeline.yaml
def labelname = "sample"

pipeline {
  agent {
    kubernetes {
      label labelname
      yaml '''
apiVersion: v1
kind: Pod
metadata:
  labels:
    sample: sample
spec:
  containers:
  - name: sample
    image: sample
    command:
    - cat
    tty: true
    resources:
      limits:
        memory: "768Mi"
        cpu: "1000m"
      requests:
        memory: "512Mi"
        cpu: "500m"
'''
    }
  }
  stages {
    stage('sample-stage') {
      steps {
        container('sample'){ 
          script {
            def sitelist = [1,2,3]

            tasks = [:]
            for (name in sitelist) {
                def siteName = name

                tasks[siteName] = {
                    container('sample'){ 
                        sh """
                            echo Hello
                        """
                    }
                }
            }
            parallel tasks
          }        
        }
      }
    }
  }
  post {
    always {
      cleanWs()
    }
  }   
}


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1