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 trueinsideparallelto abort siblings on the first failure (off by default). - A
matrixaxis value is a string; reference it as a normal env var inshsteps.
Related guides
How to Use Matrix Builds in GitHub ActionsUse GitHub Actions matrix builds to test across versions and OSes in parallel - strategy.matrix, include/excl…
How to Cache Dependencies in a Jenkins PipelineCache dependencies in a Jenkins declarative pipeline using stash/unstash or the Job Cacher plugin to persist…