Jenkins基于构建步骤的电子邮件通知

时间:2017-03-07 12:57:05

标签: jenkins jenkins-plugins

我有一个配置了两个不同构建步骤的Jenkins项目,我需要为每个构建步骤触发单独的电子邮件。有任何建议,请

1 个答案:

答案 0 :(得分:0)

编辑:您可以在每个阶段发送邮件的任何部分。

如果您使用的是Pipeline插件,那么您的Groovy脚本可能是这样的:

stage 'job-1 stage'
node('master') {
     try {
        //Run job-1 steps
     } catch(e) {
        String error = "${e}";
        // Make the string with job info, example:
        // ${env.JOB_NAME}
        // ${env.BUILD_NUMBER} 
        // ${env.BUILD_URL}
        // and other variables in the code
        mail bcc: '', body: "<b>${pivote}</b><br>\n\nMensaje de error: ${error}\n\n<br>Projecto: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "${mails_to_notify}";
        error "${error}"
    }
}

stage 'job-2 stage'
node('master') {
     try {
        //Run job-2 steps
     } catch(e) {
        String error = "${e}";
        // Make the string with job info, example:
        // ${env.JOB_NAME}
        // ${env.BUILD_NUMBER} 
        // ${env.BUILD_URL}
        // and other variables in the code
        mail bcc: '', body: "<b>${pivote}</b><br>\n\nMensaje de error: ${error}\n\n<br>Projecto: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "${mails_to_notify}";
        error "${error}"
    }
}