Skip to content

Instantly share code, notes, and snippets.

@stephanebruckert
Last active August 29, 2015 14:11
Show Gist options
  • Save stephanebruckert/d981f5e48382b83964b2 to your computer and use it in GitHub Desktop.
Save stephanebruckert/d981f5e48382b83964b2 to your computer and use it in GitHub Desktop.
Jenkins quarantine email template

Jenkins email template with Quarantine

This template is ment to be used with the Jenkins Quarantine plugin. It hides the quarantined tests from the failing test list.

To use, set ${SCRIPT, template="Groove.template"} as the Default content in your Extended E-mail Notification settings.

<style>
body table, td, th, p, h1, h2 {
font:normal normal 13px Georgia, Serif;
background-color: #ffffff;
}
h1, h2 {
border-bottom:dotted 1px #999999;
padding:5px;
color: #000000;
font: normal bold 130% Georgia,Serif;
background-color:#f0f0f0;
}
tr.gray {
background-color:#f0f0f0;
}
table {
width: 100%;
}
a {
color: #303030;
}
h2 {
padding:5px;
font: italic bold 110% Georgia,Serif;
}
.bg1 {
font-variant: small-caps;
font-weight: bold;
font-size: 25px;
}
.bg2 {
color:black;
background-color:#E0E0E0;
font-size:110%
}
td.suite_name {
width: 60%;
}
.console {
font: normal normal 70% Courier New, monotype;
}
div.content, div.header {
background: #ffffff;
border: dotted 1px #666;
}
table.border, th.border, td.border {
border: 1px solid black;
border-collapse:collapse;
}
td.right {
text-align:right;
}
.green {
color: green;
font-weight: bold;
}
.red {
color: red;
font-weight: bold;
}
</style>
<BODY>
<TABLE>
<TR><TD align="right"><IMG SRC="${rooturl}static/e59dfe28/images/32x32/<%= build.result.toString() == 'SUCCESS' ? "blue.gif" : build.result.toString() == 'FAILURE' ? 'red.gif' : 'yellow.gif' %>" />
</TD><TD valign="center"><B style="font-size: 200%;">BUILD ${build.result}</B></TD></TR>
<TR><TD></TD><TD><A href="${rooturl}${build.url}">Click here to find more information about this build</A></TD></TR>
</TABLE>
<BR/>
<%
import org.jenkinsci.plugins.quarantine.QuarantineTestAction
if (build.result.toString() == 'SUCCESS') {
%>
<p class="green">Very good job, everything is fine on this job.</p>
<%
} else {
%>
<p class="red">Something is wrong, please fix it ASAP and run another build.</p>
<!-- JUnit TEMPLATE -->
<%
def junitResultList = it.JUnitTestResult
if (junitResultList.size() > 0) { %>
<TABLE width="100%">
<TR><TD colspan="2"><span class="bg1">Unit tests that failed:</span></TD></TR>
<% it.JUnitTestResult.each{ junitResult ->
junitResult.getChildren().each { packageResult -> %>
<% packageResult.getFailedTests().each{ failed_test ->
if (!failed_test.getTestAction(QuarantineTestAction.class).quarantined) { %>
<TR bgcolor="white"><TD class="test_failed" colspan="2"><li>${failed_test.getFullName()} </li></TD></TR>
<% }
}
}
}
} %>
</TABLE>
<BR/>
<% } %>
<!-- CHANGE SET -->
<% def changeSet = build.changeSet
if(changeSet != null) {
def hadChanges = false %>
<TABLE width="100%">
<TR><TD class="bg1" colspan="2">Is it due to the following changes?</TD></TR>
<% changeSet.each() { cs ->
hadChanges = true %>
<TR>
<TD colspan="2" class="bg2">&nbsp;&nbsp;Revision <B><%= cs.metaClass.hasProperty('commitId') ? cs.commitId : cs.metaClass.hasProperty('revision') ? cs.revision :
cs.metaClass.hasProperty('changeNumber') ? cs.changeNumber : "" %></B> by
<B><%= cs.author %>: </B>
<B>(${cs.msgAnnotated})</B>
</TD>
</TR>
<% cs.affectedFiles.each() { p -> %>
<TR>
<TD width="10%">&nbsp;&nbsp;${p.editType.name}</TD>
<TD>${p.path}</TD>
</TR>
<% }
}
if(!hadChanges) { %>
<TR><TD colspan="2">No Changes</TD></TR>
<% } %>
</TABLE>
<BR/>
<% }
if (build.result.toString() != 'SUCCESS') {
%>
<!-- ARTIFACTS -->
<% def artifacts = build.artifacts
if(artifacts != null && artifacts.size() > 0) { %>
<TABLE width="100%">
<TR><TD class="bg1"><B>BUILD ARTIFACTS</B></TD></TR>
<TR>
<TD>
<% artifacts.each() { f -> %>
<li>
<a href="${rooturl}${build.url}artifact/${f}">${f}</a>
</li>
<% } %>
</TD>
</TR>
</TABLE>
<BR/>
<% } %>
<!-- MAVEN ARTIFACTS -->
<%
try {
def mbuilds = build.moduleBuilds
if(mbuilds != null) { %>
<TABLE width="100%">
<TR><TD class="bg1"><B>BUILD ARTIFACTS</B></TD></TR>
<%
try {
mbuild.each() { m -> %>
<TR><TD class="bg2"><B>${m.key.displayName}</B></TD></TR>
<% m.value.each() { mvnbld ->
def artifactz = mvnbld.artifacts
if(artifactz != null && artifactz.size() > 0) { %>
<TR>
<TD>
<% artifactz.each() { f -> %>
<li>
<a href="${rooturl}${mvnbld.url}artifact/${f}">${f}</a>
</li>
<% } %>
</TD>
</TR>
<% }
}
}
} catch(e) {
// we don't do anything
} %>
</TABLE>
<BR/>
<% }
}catch(e) {
// we don't do anything
}
%>
<!-- CONSOLE OUTPUT -->
<% if(build.result==hudson.model.Result.FAILURE) { %>
<TABLE width="100%" cellpadding="0" cellspacing="0">
<TR><TD class="bg1"><B>CONSOLE OUTPUT</B></TD></TR>
<% build.getLog(100).each() { line -> %>
<TR><TD class="console">${org.apache.commons.lang.StringEscapeUtils.escapeHtml(line)}</TD></TR>
<% } %>
</TABLE>
<BR/>
<% }
}%>
</BODY>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment