[英]How to trigger stage B only when stage A fails in jenkins pipeline
I have two stages in a jenkins Pipeline.我在 jenkins 管道中有两个阶段。 Stage A and then Stage B. I would like to trigger stage B only if stage A fails.
阶段 A,然后是阶段 B。我只想在阶段 A 失败时触发阶段 B。 If stage A is successful then skip stage B. How can I achieve this one?
如果 A 阶段成功,则跳过 B 阶段。我怎样才能实现这一目标?
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 {}
}
}
}
You can use try and catch block, and put stage B in catch block.您可以使用 try 和 catch 块,并将阶段 B 放在 catch 块中。 You need to catch the error/exception though
您需要捕获错误/异常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.