【问题标题】:Jenkins Email notification based on build stepJenkins 基于构建步骤的电子邮件通知
【发布时间】:2017-03-07 22:14:46
【问题描述】:

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

【问题讨论】:

  • 你在这两个构建步骤中做了什么?他们会生成任何日志吗?

标签: jenkins jenkins-plugins


【解决方案1】:

编辑:您可以根据需要在脚本的任何部分发送邮件。

如果您使用的是 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}"
    }
}

【讨论】:

    猜你喜欢
    • 2018-05-24
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多