Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
  }
}
like image 928
puneeth Avatar asked Aug 22 '17 12:08

puneeth


1 Answers

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       
}
like image 53
ANIL Avatar answered Sep 21 '22 07:09

ANIL