在 Jenkins 中从管道中止当前构建 [英] Abort current build from pipeline in Jenkins

查看:12
本文介绍了在 Jenkins 中从管道中止当前构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个阶段的 Jenkins 管道,例如:

node("nodename") {阶段(结帐"){混帐……}阶段(检查前提条件"){...如果(!继续构建){//我在这里放什么?当前构建.xxx ?}}阶段(做很多工作"){……}}

如果不满足某些先决条件并且没有实际工作要做,我希望能够取消(不失败)构建.我怎样才能做到这一点?我知道 currentBuild 变量可用,但我找不到它的文档.

解决方案

可以将构建标记为 ABORTED,然后使用

I have a Jenkins pipeline which has multiple stages, for example:

node("nodename") {
  stage("Checkout") {
    git ....
  }
  stage("Check Preconditions") {
    ...
    if(!continueBuild) {
      // What do I put here? currentBuild.xxx ?
    }
  }
  stage("Do a lot of work") {
    ....
  }
}

I want to be able to cancel (not fail) the build if certain preconditions are not met and there is no actual work to be done. How can I do this? I know the currentBuild variable is available, but I can't find the documentation for it.

解决方案

You can mark the build as ABORTED, and then use the error step to cause the build to stop:

if (!continueBuild) {
    currentBuild.result = 'ABORTED'
    error('Stopping early…')
}

In the Stage View, this will show that the build stopped at this stage, but the build overall will be marked as aborted, rather than failed (see the grey icon for build #9):

这篇关于在 Jenkins 中从管道中止当前构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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