How to Run a Matrix Across OS Agents in a Jenkins Pipeline
The Jenkins matrix directive fans a stage across OS agents by using an axis value as the agent label.
Define a PLATFORM axis whose values are agent labels, set the inner agent { label "${PLATFORM}" }, and the matrix runs the stages on each OS in parallel.
Matrix with a platform axis
Each axis value is an agent label; the matrix runs the inner stages on each OS node concurrently.
Jenkinsfile
pipeline {
agent none
stages {
stage('Cross-platform test') {
matrix {
axes {
axis { name 'PLATFORM'; values 'linux', 'windows', 'mac' }
}
agent { label "${PLATFORM}" }
stages {
stage('Test') {
steps { sh 'npm ci && npm test' }
}
}
}
}
}
}Gotchas
- Each axis value must correspond to a real agent label, or that combination waits forever for a node.
- Windows agents run
bat, notsh- branch onPLATFORMfor platform-specific steps. - Use
excludesinsidematrixto drop combinations you do not want to run.
Related guides
How to Run a Build Across Multiple Operating Systems in GitHub ActionsRun a GitHub Actions build across Linux, macOS, and Windows with strategy.matrix on runs-on, including includ…
How to Run Parallel Stages in a Jenkins PipelineRun parallel stages in a Jenkins declarative pipeline with the parallel block, plus matrix for fanning a stag…