![持续集成之Jenkins插件使用(二)- 邮件通知模板化 - 网易杭州QA - 网易杭州 QA Team](http://img2.ph.126.net/F5SHby3P1a7bagWiDAdigw==/3140979265214488280.png)
- 本次构建的基本信息,包括构建结果/构建url/项目名/构建开始时间/构建持续时间
![持续集成之Jenkins插件使用(二)- 邮件通知模板化 - 网易杭州QA - 网易杭州 QA Team](http://img0.ph.126.net/h52_BJi7OxpJEKLXbc00pg==/2871889187478917052.png)
- 本次构建相关的SCM改动信息
![持续集成之Jenkins插件使用(二)- 邮件通知模板化 - 网易杭州QA - 网易杭州 QA Team](http://img0.ph.126.net/OMug1ore7V5zhE4uPhb94w==/821906932095251925.png)
- 本次构建的产出物
![持续集成之Jenkins插件使用(二)- 邮件通知模板化 - 网易杭州QA - 网易杭州 QA Team](http://img2.ph.126.net/BWJnVhy2UxVF1P6M58ZSdQ==/6599319367446847619.png)
- 本次构建的console输出
![持续集成之Jenkins插件使用(二)- 邮件通知模板化 - 网易杭州QA - 网易杭州 QA Team](http://img2.ph.126.net/HtReADiu7889GHsKcG8zpQ==/6597323753844017609.png)
- 获取当前job中的参数信息。如果在SCM里配置了SVN或是GIT,大家都知道可以在job里使用${SVN_REVISION}和${GIT_REVISION}来获取版本库信息,那在Groovy脚本的邮件模板中呢?答案是可以通过以下的代码来实现
<% def svnRevision = build.getEnvironment()["SVN_REVISION"] %>
<% def svnUrl = build.getEnvironment()["SVN_URL"] %>
- 获取当前job的下游job信息。要注意的是,得到的是一个map,也就是说是一个无序的结果
<% def downstreamBuildsMap = build.getDownstreamBuilds() %>
- 通过获取触发条件得到上游job的信息。
关于详细的Jenkins API,可以参考<%
def printCausesRecursively(cause, upstreamBuilds) {
pattern = /project "(.*)" build number ([0-9]+)/
if (cause.class.toString().contains("UpstreamCause")) {
matcher = (cause.getShortDescription() =~ pattern)
if (matcher) {
job_name = matcher[0][1]
build_number = matcher[0][2]
upstream_job = hudson.model.Hudson.instance.getItem(job_name)
upstream_build = upstream_job.getBuildByNumber(build_number.toInteger())
upstreamBuilds.push(upstream_build)
upstreamBuildDuration = upstreamBuildDuration + upstream_build.duration.toInteger()
if (upstream_build.result.toString() == 'FAILURE') {
upstreamBuildStatus = 'FAILURE'
}
}
for (upCause in cause.upstreamCauses) {
printCausesRecursively(upCause, upstreamBuilds)
}
}
}
for (cause in build.causes) {
upstreamBuilds = []
printCausesRecursively(cause, upstreamBuilds)
upstreamBuilds = upstreamBuilds.reverse()
}%>