Jenkinsfile发送邮件配置

2020-01-14  本文已影响0人  阿B咬佢只鸡

1、 jenkins安装 Email Extension Plugin插件

2、配置邮箱设置
系统管理 ==> 系统设置 ==> Extended E-mail Notification

jenkins配置邮箱.png

3、 Jenkinsfile文件新增post设置
jenkins通知参考

pipeline { 
    agent any 

    environment {
        省略内容……
    }
    stages {
        stage('Build') { 
            steps {
                // 
            }
        }
        stage('Test') { 
            steps {
                // 
            }
        }
        stage('Prod') { 
            steps {
                // 
            }
        }
    }
    post {             //新增
        success {
            emailext (
                subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
                body: """<p>SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
                    <p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
                to: "user1@qq.com,user2@qq.com",
                from: "admin@sina.com"
            )
        }
        failure {
            emailext (
                subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
                body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
                    <p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
                to: "user1@qq.com,user2@qq.com",
                from: "admin@sina.com"
            )
        }
    }
}

参数解析

body (html格式)

body: '''<!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    </head>
    <body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
        <table width="95%" cellpadding="0" cellspacing="0" style="font-size: 16pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
            <tr>
                <td><br />
                    <b><font color="#0B610B"><font size="6">构建信息</font></font></b>
                    <hr size="2" width="100%" align="center" /></td>
            </tr>
            <tr>
                <td>
                    <ul>
                    <div style="font-size:18px">
                        <li>构建名称>>分支:${PROJECT_NAME}</li>
                        <li>构建结果:<span style="color:green"> Successful </span></li>
                        <li>构建编号:${BUILD_NUMBER}</li>
                        <li>触发用户:${CAUSE}</li>
                        <li>变更概要:${CHANGES}</li>
                        <li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
                        <li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
                        <li>变更集:${JELLY_SCRIPT}</li>
                    </div>
                    </ul>
                </td>
            </tr>
        </table></font>
    </body>
    </html>''',

4、邮件内容1 (未使用HTML)

邮件内容1.png
邮件内容2 (使用HTML) 邮件内容2.png
上一篇下一篇

猜你喜欢

热点阅读