jenkinsfile发送电子邮件通知

时间:2018-11-30 09:22:19

标签: jenkins jenkins-pipeline

嗨,我试图在Jenkins的构建失败时发送电子邮件警报

node ('abc') {
  stage ('checkout'){
   some codes inside
   }

  stage ('build'){
    some code inside
  }

  stage ('test') {
    some code inside
   }

  stage ('deploy'){
  some code inside
  }

  post {
    failure {
        mail bcc: '', body: '''Hi, 

        The pipeline at Jenkins has failed. Pleas go over to the Jenkins and 
         check it out.

         Thanks!''', cc: '', from: '', replyTo: '', subject: 'The pipeline has failed!', to: 'abc@gmail.com'
        }
    }

}

我收到

的错误消息
  

java.lang.NoSuchMethodError:在这样的DSL方法“ post”中找不到   步骤

2 个答案:

答案 0 :(得分:0)

请参阅詹金斯官方文档: https://jenkins.io/doc/pipeline/tour/running-multiple-steps/#finishing-up (如果您不想使用声明性管道,请参见“切换脚本化管道”部分。)

答案 1 :(得分:0)

您可以通过执行id块来实现。

try-catch-finally