首页 > 解决方案 > Jenkins Job DSL 在 postBuildScripts shell 中获取当前构建结果

问题描述

我需要在我的 Jenkins DSL 脚本中的 postBuildScripts shell 调用中获取当前构建执行的结果。就像${currentBuild.currentResult}在具有值的 Jenkins 管道中一样:SUCCESS、UNSTABLE 或 FAILURE

我已经搜索了 DSL 文档,但没有找到任何解决方案。

我的代码是这样的:

postBuildScripts {
  steps {
    shell("""echo \$CURRENT_BUILD_STATUS""")
  }
}

那么如何以$CURRENT_BUILD_STATUS最简单的方式得到这个呢?

标签: jenkinsjenkins-job-dsl

解决方案


不幸的是,PostBuildScript 插件的文档缺少一些有趣的部分......

job('example') {
  publishers {
    postBuildScripts {
      steps {
        shell('echo $BUILD_RESULT')
      }
    }
  }
}

推荐阅读