最终邮件结果
背景
Jenkins定时构建完之后发送邮件,每次查看邮件只有构建信息,没有把测试结果在邮件中上体现出来,而是要从邮件链接去访问,才能看到测试报告,如果没有账号,无法登录查看报告,这样也比较影响效果。
由于想从邮件结果直接看到测试结果,从而想把报告直接扩展在邮件内容里面。
邮件配置实现
Jenkins配置pipline邮件内容,在job设置,在Pipeline设置添加邮件发送内容
1、优化前
body: '(本邮件是程序自动下发的,请勿回复!)<br/><hr/>项目名称:${PROJECT_NAME}<br/><hr/>构建编号:${BUILD_NUMBER}<br/><hr/>触发原因:${CAUSE}<br/><hr/>部署分支:${gitBranch}<br/><hr/>部署状态:Successful<br/><hr/>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a><br/><hr/>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a><br/><hr/>环境: ${environment}<br/><hr/>变更概要:${CHANGES}<br/><hr/>测试报告地址:<a href=${BUILD_URL}HTML_20Report>${BUILD_URL}HTML_20Report</a><br/><hr/>变更集:${JELLY_SCRIPT}<br/><hr/>',
subject: '${gitName}执行结果:Successful - ${PROJECT_NAME} - Build # ${BUILD_NUMBER} !',
to: '${noticeEmail}',
发送邮件内容:
2、优化后
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>部署分支:${gitBranch}</li>
<li>构建地址:<a href=${BUILD_URL}>${BUILD_URL}</a></li>
<li>构建日志:<a href=${BUILD_URL}console>${BUILD_URL}console</a></li>
<li>环境: ${environment}</li>
<li>测试阶段:${execute_stage}</li>
<li>变更概要:${CHANGES}</li>
<li>测试报告地址:<a href=${BUILD_URL}HTML_20Report>${BUILD_URL}HTML_20Report</a></li>
<li>变更集:${JELLY_SCRIPT}</li>
<li><font color="#0B610B"><font size="6">测试结果报告</font></font> ${FILE, path="/opt/htdocs/jenkins/reports/soa/html/${parameter}/${parameter_name}_Report.html"}
</div>
</ul>
</td>
</tr>
</table></font>
</body>
</html>''',
发送邮件内容