Issue
I have two stages in a jenkins Pipeline. Stage A and then Stage B. I would like to trigger stage B only if stage A fails. If stage A is successful then skip stage B. How can I achieve this one ?
Solution
Try as below:
def stageA_Fail = false
pipeline {
stages {
stage('A') {
steps {
script {
try {
// put all steps of stage A in try
}
catch() {
stageA_Fail = true
}
}
}
}
stage('B') {
when {expression {return stageA_Fail} }
steps {}
}
}
}
Answered By - yong