How to run parallel stages in isolated pods for a declarative jenkins pipeline
Try something like this
stage("Run additional parallel tests") { parallel( "parallel stage 1": { [INSERT YOUR CODE HERE] }, "parallel stage 2": { [INSERT YOUR CODE HERE] } ) }}
You can set agent {}
for each parallel stage to launch a pod per stage.
You have__________: stage > parallel > stage > steps
.
You need to have also: stage > parallel > stage > agent
.
Do not repeat pod definition twice, it is recommended to put the pod definition in a separated file and refer to it using yamlFile
instead of yaml
:
stage('Test'){ parallel { stage("Branch 1") { agent { kubernetes { defaultContainer 'jnlp' yamlFile 'Jenkins.pod.yaml' } } steps { container('<tests-container-name>') { sh "jenkins/scripts/initdb.sh" sh 'bundle exec rspec --exclude-pattern "spec/features/*_spec.rb" spec' } } } stage("Branch 2") { agent { kubernetes { defaultContainer 'jnlp' yamlFile 'jenkins.pod.yaml' } } steps { container('<tests-container-name>') { sh "jenkins/scripts/initdb.sh" sh "bundle exec rspec `jenkins/scripts/split_features.sh 0`" } } } } }
Hint
if blueocean is one of your plugins, it will help you to draw your pipeline under http://HOST/blue/organizations/jenkins/pipeline-editor/
, then you can copy the Jenkinsfile code by typing [Cmd + s]