前言
当构建失败之后,发送邮件通知相关的人员,创建只读用户让相关人员查看日志。
安装发送邮件插件
Email Extension Plugin
配置管理员邮箱
Dashboard --> 系统管理 --> system
测试邮件发送
SMTP的授权码,可以搜索“QQ的SMTP的授权码怎么开”
测试成功之后,可以开始配置了
找到Extended E-mail Notification这一项
凭证的类型选择如下
内容如下
<body>
<head>
<STYLE TYPE="text/css">
BODY {
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size:100% 100%;
}
</STYLE>
</head>
<h2 style="color: #5e9ca0; text-align: center;">Jenkins构建失败邮件,请检查相关日志!</h2>
<table class="editorDemoTable" style="height: 273px;" width="430">
<thead>
<tr>
<td nowrap="nowrap" style="background-color: #3498db; text-align: center;" colspan="2">
<h2><span style="color: #000000;">构建报告</span></h2>
</td>
</tr>
</thead>
<tbody>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">项目名称:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">$PROJECT_NAME</span></td>
</tr>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">构建编号:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">$BUILD_NUMBER</span></td>
</tr>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">构建状态:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">$BUILD_STATUS</span></td>
</tr>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">触发原因:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">${CAUSE}</span></td>
</tr>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">构建日志地址:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #00ccff;"> <a style="color: #00ccff;" title="构建日志" href="${BUILD_URL}console">${BUILD_URL}console</a></span></td>
</tr>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">构建地址:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #00ccff;"> <a style="color: #00ccff;" title="构建地址" href="$BUILD_URL">$BUILD_URL</a></span></td>
</tr>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">测试报告地址:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #00ccff;"><a style="color: #00ccff;" title="测试报告地址" href="${BUILD_URL}robot/report/report.html">${BUILD_URL}robot/report/report.html</a></span></td>
</tr>
<tr>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #808000;">测试日志地址:</span></td>
<td nowrap="nowrap" style="border-color: gray;"><span style="color: #00ccff;"> <a style="color: #00ccff;" title="测试日志地址" href="${BUILD_URL}robot/report/log.html">${BUILD_URL}robot/report/log.html</a></span></td>
</tr>
</tbody>
</table>
</body>
开启调试模块,会打印更多的日志
Jenkins项目测试
新建一个test项目
选择构建步骤 --> 执行shell,打一个不存在的shell命令,让构建失败。
添加构建后的步骤,选择
Editable Email Notification
保存,开始构建测试