简体   繁体   中英

Jenkins declarative pipeline parallel steps executors

I am migrating a job from multijob to a Jenkins Declarative pipeline job. I am unable to run the parallel steps on multiple executors.

For example in the pipeline below, I see only one executor being used when I run the pipeline.

I was wondering why only a single executor is used. The idea is that each parallel step would be inoking a make target that would build a docker image.

pipeline {
  agent none
  stages {
    stage('build libraries') {
      agent { label 'master' }
      steps {
        parallel(
          "nodejs_lib": {
            dir(path: 'nodejs_lib') {
                sh 'sleep 110'
            }
          },
          "python_lib": {
            dir(path: 'python_lib') {
              sh 'sleep 100'
            }
          }
        )
      }
    }
  }
  options {
    ansiColor('gnome-terminal')
    buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '30'))
    timestamps()
  }
}

You can try the following way to perform parallel tasks execution for your pipeline job:

def tasks = [:]

            tasks["TasK No.1"] = {
              stage ("TASK1"){    
                node('master') {  
                    sh '<docker_build_command_here>'
                }
              }
            }
            tasks["task No.2"] = {
              stage ("TASK2"){    
                node('master') {  
                    sh '<docker_build_command_here>'
                }
              }
            }
            tasks["task No.3"] = {
              stage ("TASK3"){    
                node('remote_node') {  
                    sh '<docker_build_command_here>'
                }
              }
            }

 parallel tasks       

If you want to execute parallel tasks on a single node and also want to have the same workspace for both the tasks then you can go with the following approach:

node('master') { 

def tasks = [:]

                tasks["TasK No.1"] = {
                  stage ("TASK1"){    

                        sh '<docker_build_command_here>'
                  }
                }
                tasks["task No.2"] = {
                  stage ("TASK2"){    

                        sh '<docker_build_command_here>'
                  }
                }


     parallel tasks       
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM