How do you run stages in parallel in a Jenkins declarative pipeline?
IntermediateConceptJenkins
Answer
Use a parallel block inside a stage. Each child stage can have its own agent. Add failFast true so the other branches abort when one fails.
stage('Tests') {
failFast true
parallel {
stage('Unit') { steps { sh 'make unit' } }
stage('Integration') { agent { label 'docker' } steps { sh 'make integration' } }
stage('Lint') { steps { sh 'make lint' } }
}
}
Parallel branches compete for executors, so more parallelism only helps if agents are available.
More on Jenkins
What is Jenkins and how is its architecture organised?BeginnerWhat are executors, nodes and labels in Jenkins?IntermediateWhy should you not run builds on the Jenkins controller?BeginnerHow do inbound (JNLP/WebSocket) and SSH agents connect to the controller?IntermediateWhat is a Jenkinsfile and where does it live?BeginnerDeclarative versus Scripted Pipeline: what are the differences?Intermediate