jenkins - 构建恢复时如何在 Jenkins 管道中发送通知?

标签 jenkins notifications jenkins-pipeline

我想在作业恢复时从我的 Jenkins 管道构建发送通知。意思是当前构建成功而上次构建错误(失败、中止等)。

我知道如何发送通知。我认为我的问题归结为如何检查以前构建的状态,但我可能会弄错。

我试过“currentBuild.rawBuild.getPreviousBuild()?.getResult()”,但得到异常“org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not allowed to use method org.jenkinsci.plugins.workflow.support.步骤.build.RunWrapper getRawBuild”。如果我关闭沙箱,它应该可以工作。沙箱可以吗?

最佳答案

我找到了另一个可行的解决方案,它不需要您手动跟踪构建结果。虽然,它需要使用脚本元素:(

pipeline {
  agent any
  post {
    success {
      script {
        if (currentBuild.getPreviousBuild() && 
            currentBuild.getPreviousBuild().getResult().toString() != "SUCCESS") {
          echo 'Build is back to normal!'
        }
      }
    }
  }
}

关于jenkins - 构建恢复时如何在 Jenkins 管道中发送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42577953/

相关文章:

java - 禁用 Jenkins 作业 x 小时

使用参数化触发器插件触发的 Jenkins 构建被触发它的作业阻止

javascript - 可以通过浏览器访问远程 json 组件,但不能通过 $.getJSON() 以编程方式访问

iOS -- 我想更改语言警报推送通知

ruby-on-rails - 在 Rails 中实现通知

maven - 如何使用带有管道的 Docker 缓存本地 Maven 存储库?

jenkins - Jenkins 中的构建超时插件 : how long is 'too long' ?

Jenkins 可锁定资源 - 无需解锁即可锁定

sed - 使用 SED 命令用 Jenkinsfile 中的变量替换字符串

jquery - 如何在asp.net中创建一次性通知系统