I want to define multiple stages in Jenkins declarative pipeline syntax which can continue past any one of them failing. I cannot find any existing questions which are true dupl
I think it depends on how dependent the jobs are on each other. Derived from your example I would assume that
So the correpsonding pipeline could be
pipeline {
stages {
stage('Independent tasks') {
parallel {
stage('stage 1') {
steps {
sh 'exit 1' // failure
}
}
stage('stage 2') {
steps {
echo 'Happens even so stage 1 fails'
sh 'exit 0' // success
}
}
}
post { // 'stage 3'
failure {
echo "... at least one failed"
}
success {
echo "Success!"
}
}
}
stage ('stage 4') {
steps {
echo 'Happens only if all previous succeed'
}
}
}
}
stage 1 and stage 2 will always run, stage 3 reacts on their combined success/failure.
Additional thought: This concept only works 'at the end' of your pipeline. In case you need it somewhere in the middle AND the build has to continue, you could move it into an own job and use the build job plugin.
pipeline {
stages {
stage('Start own job for stage 1, 2, 3') {
steps {
build job: 'stageOneTwoThree', propagate: false, wait: true
}
}
stage ('stage 4') {
steps {
echo 'Happens always, because "propagate: false"'
}
}
}