1抬旺、 jenkins安裝 Email Extension Plugin插件
2、配置郵箱設(shè)置
系統(tǒng)管理 ==> 系統(tǒng)設(shè)置 ==> Extended E-mail Notification
jenkins配置郵箱.png
3译暂、 Jenkinsfile文件新增post設(shè)置
jenkins通知參考
pipeline {
agent any
environment {
省略內(nèi)容……
}
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"
)
}
}
}
參數(shù)解析
- subject:郵件主題永淌,可以自定義
- body:郵件正文,可以自定義(例如下面的HTML)
- to:收件人列表健爬,根據(jù)實(shí)際情況定義
- from:發(fā)件人,要和步驟 2 配置的發(fā)件人一致
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">構(gòu)建信息</font></font></b>
<hr size="2" width="100%" align="center" /></td>
</tr>
<tr>
<td>
<ul>
<div style="font-size:18px">
<li>構(gòu)建名稱>>分支:${PROJECT_NAME}</li>
<li>構(gòu)建結(jié)果:<span style="color:green"> Successful </span></li>
<li>構(gòu)建編號(hào):${BUILD_NUMBER}</li>
<li>觸發(fā)用戶:${CAUSE}</li>
<li>變更概要:${CHANGES}</li>
<li>構(gòu)建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
<li>構(gòu)建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
<li>變更集:${JELLY_SCRIPT}</li>
</div>
</ul>
</td>
</tr>
</table></font>
</body>
</html>''',
4么介、郵件內(nèi)容1 (未使用HTML)
郵件內(nèi)容1.png
郵件內(nèi)容2 (使用HTML)
郵件內(nèi)容2.png