Create parallel jenkins jobs

Define parallel stages in a Jenkins pipeline with a Groovy Jenkinsfile.

1 min read Updated

Jenkins pipelines can run stages in parallel by building a map of closures and handing it to the parallel step. This Jenkinsfile shows the pattern with two jobs. The pipeline is reproduced below.

Jenkinsfile

text
def jobs = [:]

jobs["jobs-testa"] = {
  node {
    stage("Build testa") {
      echo ">>> testa"
    }
  }
}

jobs["jobs-testb"] = {
  node {
    stage("Build testb") {
      echo ">>> testb"
    }
  }
}

pipeline {
  agent none
  stages {
    stage('Build apps(s)') {
      steps {
        script {
          parallel jobs
        }
      }
    }
  }
}

Search articles

Type to filter articles. Use the arrow keys to move through results and Enter to open one. Press Escape to close.