第一步,服务器上jenkins home(/home/jenkins/dataspace)目录中创建了email-templates文件夹
第二步,上传模板(default.template)到email-templates文件夹
第三步,在job配置中的Default Content中写入${SCRIPT, template="default.template"},邮件样式大致(下图是我自己稍修改的模板样式,与default.template稍微有点差别):
附default.template:
BODY, TABLE, TD, TH, P {
font-family: Calibri, Verdana, Helvetica, sans serif;
font-size: 12px;
color: black;
}
.console {
font-family: Courier New;
}
.filesChanged {
width: 10%;
padding-left: 10px;
}
.section {
width: 100%;
border: thin black dotted;
}
.td-title-main {
color: white;
font-size: 200%;
padding-left: 5px;
font-weight: bold;
}
.td-title {
color: white;
font-size: 120%;
font-weight: bold;
padding-left: 5px;
text-transform: uppercase;
}
.td-title-tests {
font-weight: bold;
font-size: 120%;
}
.td-header-maven-module {
font-weight: bold;
font-size: 120%;
}
.td-maven-artifact {
padding-left: 5px;
}
.tr-title {
background-color: <%= (build.result == null || build.result.toString() == 'SUCCESS') ? '#27AE60' : build.result.toString() == 'FAILURE' ? '#E74C3C' : '#f4e242' %>;
}
.test {
padding-left: 20px;
}
.test-fixed {
color: #27AE60;
}
.test-failed {
color: #E74C3C;
}
BUILD ${build.result ?: 'COMPLETED'}
Project:
${project.name}
BUILD_URL:
Date:
${it.timestampString}
Duration:
${build.durationString}
Cause:
<% build.causes.each() { cause -> %> ${cause.shortDescription} <% } %>
<%
def changeSets = build.changeSets
if(changeSets != null) {
def hadChanges = false %>
CHANGES
<% changeSets.each() {
cs_list -> cs_list.each() {
cs -> hadChanges = true %>
Revision
<%= cs.metaClass.hasProperty('commitId') ? cs.commitId : cs.metaClass.hasProperty('revision') ? cs.revision : cs.metaClass.hasProperty('changeNumber') ? cs.changeNumber : "" %>
by <%= cs.author %>
${cs.msgAnnotated}
<% cs.affectedFiles.each() {
p -> %>
${p.editType.name}
${p.path}
<% }
}
}
if ( !hadChanges ) { %>
No Changes
<% } %>
<% } %>
<%
def artifacts = build.artifacts
if ( artifacts != null && artifacts.size() > 0 ) { %>
BUILD ARTIFACTS
<% artifacts.each() {
f -> %>
<% } %>
<% } %>
<%
try {
def mbuilds = build.moduleBuilds
if ( mbuilds != null ) { %>
BUILD ARTIFACTS
<%
try {
mbuilds.each() {
m -> %>
${m.key.displayName}
<%
m.value.each() {
mvnbld -> def artifactz = mvnbld.artifacts
if ( artifactz != null && artifactz.size() > 0) { %>
<% artifactz.each() {
f -> %>
<% } %>
<% }
}
}
} catch(e) {
// we don't do anything
} %>
<% }
} catch(e) {
// we don't do anything
} %>
<%
def junitResultList = it.JUnitTestResult
try {
def cucumberTestResultAction = it.getAction("org.jenkinsci.plugins.cucumber.jsontestsupport.CucumberTestResultAction")
junitResultList.add( cucumberTestResultAction.getResult() )
} catch(e) {
//cucumberTestResultAction not exist in this build
}
if ( junitResultList.size() > 0 ) { %>
${junitResultList.first().displayName}
Name
Failed
Passed
Skipped
Total
<% junitResultList.each {
junitResult -> junitResult.getChildren().each {
packageResult -> %>
${packageResult.getName()}
${packageResult.getFailCount()}
${packageResult.getPassCount()}
${packageResult.getSkipCount()}
${packageResult.getPassCount() + packageResult.getFailCount() + packageResult.getSkipCount()}
<% packageResult.getPassedTests().findAll({it.getStatus().toString() == "FIXED";}).each{
test -> %>
${test.getFullName()} ${test.getStatus()}
<% } %>
<% packageResult.getFailedTests().sort({a,b -> a.getAge() <=> b.getAge()}).each{
failed_test -> %>
${failed_test.getFullName()} (Age: ${failed_test.getAge()})
<% }
}
} %>
<% } %>
<%
if ( build.result == hudson.model.Result.FAILURE ) { %>
CONSOLE OUTPUT
<% build.getLog(100).each() {
line -> %>
${org.apache.commons.lang.StringEscapeUtils.escapeHtml(line)}
<% } %>
<% } %>