展示Jenkins管道舞台失败而不会失败整个工作 [英] Show a Jenkins pipeline stage as failed without failing the whole job
本文介绍了展示Jenkins管道舞台失败而不会失败整个工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我正在玩的代码
节点{
阶段'build'
回声'build'
阶段'测试'
回声'测试'
阶段'端到端测试'
def e2e =构建作业:'end-to-end-testing',传播:false
result = e2e.result
if(result.equals(SUCCESS)){
stage'deploy'
构建'deploy'
} else {
??????我想在这个阶段失败
code
$ b $ p
有什么办法吗?对我来说,把'端对端测试'阶段标记为失败而不会失败整个工作?传播虚假总是将舞台标记为真实,这不是我想要的,但传播真实会将作业标记为失败,我也不想这样做。
解决方案
舞台现在需要一个方块,所以将舞台换成try-catch。 Try-catch在舞台上取得成功。
前面提到的新功能将更加强大。同时:
try {
stage('end-to-end-tests'){
节点{
def e2e =构建作业:'端对端测试',传播:false
result = e2e.result
if(result.equals(SUCCESS)) {
} else {
shexit 1// this stage the stage
}
}
}
} catch(e){
result =FAIL//确保其他异常记录为失败
stage('deploy'){
if(result.equals(SUCCESS )){
build'deploy'
} else {
echo无法成功构建就无法部署//对于当前可视化文件$ b $,甚至有一个部署阶段也很重要b}
}
Here's the code I'm playing with
node {
stage 'build'
echo 'build'
stage 'tests'
echo 'tests'
stage 'end-to-end-tests'
def e2e = build job:'end-to-end-tests', propagate: false
result = e2e.result
if (result.equals("SUCCESS")) {
stage 'deploy'
build 'deploy'
} else {
?????? I want to just fail this stage
}
}
Is there any way for me to mark the 'end-to-end-tests' stage as failed without failing the whole job? Propagate false just always marks the stage as true, which is not what I want, but Propagate true marks the job as failed which I also don't want.
解决方案
Stage takes a block now, so wrap the stage in try-catch. Try-catch inside the stage makes it succeed.
The new feature mentioned earlier will be more powerful. In the meantime:
try {
stage('end-to-end-tests') {
node {
def e2e = build job:'end-to-end-tests', propagate: false
result = e2e.result
if (result.equals("SUCCESS")) {
} else {
sh "exit 1" // this fails the stage
}
}
}
} catch (e) {
result = "FAIL" // make sure other exceptions are recorded as failure too
}
stage('deploy') {
if (result.equals("SUCCESS")) {
build 'deploy'
} else {
echo "Cannot deploy without successful build" // it is important to have a deploy stage even here for the current visualization
}
}
这篇关于展示Jenkins管道舞台失败而不会失败整个工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文