在Jenkins Pipelines中设置舞台状态 [英] Set a stage status in Jenkins Pipelines

查看:269
本文介绍了在Jenkins Pipelines中设置舞台状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本流水线中是否有任何方法可以将一个阶段标记为不稳定,而仅在不将每个阶段标记为不稳定的情况下将该阶段标记为不稳定?

Is there any way in a scripted pipeline to mark a stage as unstable but only show that stage as unstable without marking every stage as unstable in the output?

我可以做这样的事情:

node()
{
  stage("Stage1")
  {
      // do work (passes)
  }
  stage("Stage2")
  {
      // something went wrong, but it isn't catastrophic...
      currentBuild.result = 'UNSTABLE'
  }
  stage("Stage3")
  {
      // keep going... 
  }
}

但是,当我运行此程序时,詹金斯将所有内容标记为不稳定...但是我希望第一级和最后一级在可能的情况下显示绿色,而在出现黄色问题的阶段只是这样.

But when I run this, Jenkins marks everything as unstable... but I'd like the first and last stages to show green if possible and just the stage that had an issue to go yellow.

如果整个管道都被标记为不稳定是可以的,但是最好在骑行的后期进行一个阶段,并尽可能使最终结果通过.

It's ok if the whole pipeline gets flagged unstable, but it might also be nice to have a later stage over ride that and set the final-result to pass if possible too.

推荐答案

现在可以:

pipeline {
    agent any
    stages {
        stage('1') {
            steps {
                sh 'exit 0'
            }
        }
        stage('2') {
            steps {
                catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
                    sh "exit 1"
                }
            }
        }
        stage('3') {
            steps {
                sh 'exit 0'
            }
        }
    }
}

在上面的示例中,所有阶段都将执行,管道将成功,但是阶段2将显示为不稳定.我在示例中使用了声明性管道,但是在脚本化管道中应该可以使用相同的内容.

In the example above, all stages will execute, the pipeline will be successful, but stage 2 will show as unstable. I use a declarative pipeline in the example, but it should work the same in a scripted pipeline.

您可能已经猜到了,可以将buildResultstageResult随意更改为任意组合.您甚至可以使构建失败并继续执行管道.

As you might have guessed, you can freely change the buildResult and stageResult to any combination. You can even fail the build and continue the execution of the pipeline.

只需确保您的Jenkins是最新的,因为这是一个相当新的功能.升级受错误 JENKINS-39203 影响的所有插件,例如:

Just make sure your Jenkins is up to date, since this is a fairly new feature. Upgrade any plugins affected by bug JENKINS-39203, such as:

  • Pipeline Graph Analysis plugin (at least version 1.10 to mark single stages as 'UNSTABLE')
  • Pipeline Basic Steps plugin (at least version 2.18 to set stageResult in catchError)

这篇关于在Jenkins Pipelines中设置舞台状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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