Skip to content
Latchkey

How to Run Parallel Stages in a Jenkins Pipeline

Jenkins runs work concurrently with a parallel block, or fans a stage across axes with the matrix directive.

Wrap branches in parallel {} to run them at once, or use matrix {} with axes to run a stage for every combination of values.

Matrix across versions

The matrix runs the inner stages once per Node version, in parallel.

Jenkinsfile
pipeline {
  agent none
  stages {
    stage('Test') {
      matrix {
        axes {
          axis { name 'NODE_VERSION'; values '18', '20', '22' }
        }
        agent { label 'linux' }
        stages {
          stage('Run') {
            steps {
              sh 'nvm use $NODE_VERSION && npm ci && npm test'
            }
          }
        }
      }
    }
  }
}

Gotchas

  • Parallel branches need enough executors/agents - too few and they queue instead of running concurrently.
  • Use failFast true inside parallel to abort siblings on the first failure (off by default).
  • A matrix axis value is a string; reference it as a normal env var in sh steps.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →