【问题标题】:jenkinsfile send email notificationsjenkinsfile 发送电子邮件通知
【发布时间】:2018-12-01 07:43:06
【问题描述】:

您好,我尝试在 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: No such DSL method 'post' found between 步骤

【问题讨论】:

标签: jenkins jenkins-pipeline


【解决方案1】:

您可以通过执行try-catch-finally 块来实现此目的。

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

        stage ('build'){
            some code inside
        }

        stage ('test') {
            some code inside
        }

        stage ('deploy'){
            some code inside
        }

        stage ('notify'){
            Notification for JOB Success
        }
    }catch(e){
        Notification for JOB Failure
    }finally{

    }
}

【讨论】:

  • @xxxSL 你最终不需要任何东西。 Success 通知应该在try 块中的last 阶段,Failure 通知应该在代码中提到的catch 块内
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多