本文介绍了如何为Jenkins管道获得相同的Mailer行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用Jenkins声明式管道.现在,我希望具有与用法相同的电子邮件通知行为. Mailer插件:

I started using Jenkins declarative pipelines. Now I want to have the same email notification behavior as defined in the Usage of the Mailer plugin:

  1. 每次构建失败都会触发一封新电子邮件.
  2. 构建失败(或不稳定)后,构建成功会触发一封新电子邮件,表明危机已经结束.
  3. 构建成功后,不稳定的构建会触发新电子邮件,表明存在回归.
  4. 除非进行配置,否则每个不稳定的构建都会触发一封新电子邮件,表明回归仍然存在.
  1. Every failed build triggers a new e-mail.
  2. A successful build after a failed (or unstable) build triggers a new e-mail, indicating that a crisis is over.
  3. An unstable build after a successful build triggers a new e-mail, indicating that there's a regression.
  4. Unless configured, every unstable build triggers a new e-mail, indicating that regression is still there.

我阅读了管道中的通知,但它不会根据上述规则进行通知.另外,如果构建失败,它不会在消息正文中包含控制台输出的一部分.

I read about Notifications in Pipelines, but it does not notify based on above rules. Plus it does not contain part of the console output in the message body in case of a build failure.

有人知道如何在声明式管道中执行此操作吗?

Does anybody know how to do this in declarative pipeline?

推荐答案

使用以下代码,您可以在帖子部分使用mailer插件.这提供了预期的行为:

With the following code you can use the mailer plugin in the post section. This provides the expected behaviour:

pipeline {
  agent any
  stages {
      stage('test') {
        steps {
          script {
              // change to 'UNSTABLE' OR 'FAILED' to test the behaviour 
              currentBuild.result = 'SUCCESS'
          }
        }
      }
  }
  post {
        always {
          step([$class: 'Mailer',
            notifyEveryUnstableBuild: true,
            recipients: "[email protected]",
            sendToIndividuals: true])
        }
  }
}

这篇关于如何为Jenkins管道获得相同的Mailer行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 21:37