如果 Step 不稳定,Jenkins 流水线会失败 [英] Jenkins Pipeline Fails if Step is Unstable

查看:37
本文介绍了如果 Step 不稳定,Jenkins 流水线会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 maven-job 不稳定(黄色)时,目前我的管道失败(红色).

Currently my pipeline fails (red), when a maven-job is unstable (yellow).

node {
    stage 'Unit/SQL-Tests'
    parallel (
       phase1: { build 'Unit-Tests' }, // maven
       phase2: { build 'SQL-Tests' } // shell
    )
    stage 'Integration-Tests'
    build 'Integration-Tests' // maven
}

在此示例中,作业单元测试的结果不稳定,但在管道中显示为失败.

In this example the job Unit-Test's result is unstable, but is shown as failed in the pipeline.

如何更改作业/管道/jenkins 以使 (1) 管道步骤不稳定而不是失败,以及 (2) 管道的状态不稳定而不是失败.

How can I change the jobs/pipeline/jenkins to have the (1) the pipeline step unstable instead of failed and (2) the pipeline's status unstable instead of failed.

我尝试添加 MAVEN_OPTS 参数 -Dmaven.test.failure.ignore=true,但这并没有解决问题.我不确定如何将 build 'Unit-Test' 包装到一些可以捕获和处理结果的逻辑中.

I tried adding the MAVEN_OPTS parameter -Dmaven.test.failure.ignore=true, but that did not solve the issue. I am unsure how to wrap the build 'Unit-Test' into some logic that can catch and process the result.

使用 这个逻辑 不能解决问题,因为没有从 subversion 签出的选项(该选项在常规 maven 作业中可用).如果可能,我不想使用命令行结帐.

Adding a sub-pipeline with this logic doesn't do the trick, as there is no option to checkout from subversion (that option is available in a regular maven job). I would not like to use commandline checkout if possible.

推荐答案

无论该步骤是 UNSTABLE 还是 FAILED,您的脚本中的最终构建结果都将是 FAILED.

Whatever the step is UNSTABLE or FAILED, the final build result in your script will be FAILED.

您可以默认将propagation添加到false以避免流失败.

You can add propagate to false by default to avoid fail the flow.

def result = build job: 'test', propagate: false

在流程结束时,您可以根据从结果"变量中获得的结果来判断最终结果.

In the end of the flow, you can verdict the final result based on what you got from the "result" variable.

例如

currentBuild.result='UNSTABLE'

这是一个详细的例子如何设置管道中的当前构建结果

兄弟,

提姆

这篇关于如果 Step 不稳定,Jenkins 流水线会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆