How does the `matrix` directive work?
IntermediateConceptDeclarative pipeline syntax
Answer
matrix generates one parallel cell per combination of axes, with optional excludes. Each cell runs the inner stages, and axis values are available as environment variables.
stage('Test matrix') {
matrix {
axes {
axis { name 'NODE'; values '20', '22' }
axis { name 'OS'; values 'linux', 'windows' }
}
excludes { exclude { axis { name 'OS'; values 'windows' }; axis { name 'NODE'; values '20' } } }
agent { label "${OS}" }
stages { stage('Test') { steps { echo "Node ${NODE} on ${OS}" } } }
}
}
Watch the cell count: axes multiply, and large matrices can hit the JVM Method code too large limit.
More on Declarative pipeline syntax
What is the minimum valid declarative pipeline?BeginnerWhat agent types exist in declarative pipelines?IntermediateWhen do you use `agent none` at the top level?IntermediateHow do nested sequential stages work and why are they useful?IntermediateList the `post` conditions and when each fires.IntermediateWhat are the most useful `when` conditions?Intermediate