如果步骤不稳定,Jenkins管道将失败 [英] Jenkins Pipeline Fails if Step is Unstable

查看:89
本文介绍了如果步骤不稳定,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.

如何更改作业/管道/詹金斯,使(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.

使用

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.

推荐答案

无论步骤是不稳定还是失败,脚本中的最终构建结果都会失败.

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

默认情况下,您可以将传播添加为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'

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

Here is a detail example How to set current build result in Pipeline

Br,

蒂姆

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

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