【发布时间】:2017-05-16 12:30:47
【问题描述】:
我正在使用嵌套的 try-catch 块来定义 jenkins 管道。在执行时,如果我在父 try-catch 块中有另一个 try-catch 块并且子 try-catch 块出现问题,它将跳转到子 catch 块然后再次继续执行父级中的代码try-catch 块。
我已尝试设置 currentBuild.result='Failure' 和 error "Error occurred" 但仍然会继续执行。我希望管道状态为失败并终止其余代码的执行。
try{
stage('stage1'){
//do something
}
try{
stage('stage2'){
//do something
}
}catch(Exception err1){
error "Error Occurred"
currentBuild.result='Failure'
}
}catch(Exception ex){
// Do something if stage 1 fails
}
如果第 2 阶段失败,则不应跳转到第 1 阶段的 catch 语句。有人可以建议我实现这一目标的好方法吗?
【问题讨论】: