Jenkinsfile如何在并行分支中捕获多个异常
我有一个jenkins脚本,jenkins管道作业使用该脚本:Jenkinsfile如何在并行分支中捕获多个异常,jenkins,groovy,Jenkins,Groovy,我有一个jenkins脚本,jenkins管道作业使用该脚本: try{ parallel branch1: { //some function that may throw exception }, branch2: { //some function that may throw exception }, branch3: { //some function that may throw except
try{
parallel branch1: {
//some function that may throw exception
}, branch2: {
//some function that may throw exception
}, branch3: {
//some function that may throw exception
}
}catch(Exception e){
//Need to gather the error information together.
//if there is only 1 error then that's it;
//if there are 2 or more errors then concatenate them or so, etc.. and print it.
}
如何获取这些分支中的所有异常?或者我就是做不到?假设您能够以某种方式将错误捕获到变量中,捕获输出并将其存储到结束阶段。然后,您所要做的就是将每个阶段的构建结果设置为成功,以防止作业过早失败。请参阅以了解如何做到这一点。最后,在末尾连接变量 最终结果可能看起来像(半伪代码) 我甚至可能在尝试/捕获之外,仅仅依靠设置
currentBuild.result
s来处理错误
try{
parallel branch1: {
//some function that may throw exception
error1=$(echo error)
currentBuild.result = 'SUCCESS'
return
}, branch2: {
//some function that may throw exception
error2=$(echo error)
currentBuild.result = 'SUCCESS'
return
}, branch3: {
//some function that may throw exception
error3=$(echo error)
currentBuild.result = 'SUCCESS'
return
}
}catch(Exception e){
//gather the error information together (if there 1 error then just it, if there are 2 errors then concatenate 2 errors together, etc) and print it.
print $error1 + $error2 + $error3
}