Skip to content

Instantly share code, notes, and snippets.

@nightspotlight
Last active February 8, 2022 12:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nightspotlight/7cfa6af7c7989857f336f742cdcb443b to your computer and use it in GitHub Desktop.
Save nightspotlight/7cfa6af7c7989857f336f742cdcb443b to your computer and use it in GitHub Desktop.
Jelly template to display table with JUnit test results for Jenkins Email-ext plugin
<?jelly escape-by-default='true'?>
<!DOCTYPE html [
<!ENTITY nbsp "&#38;#38;nbsp&#59;">
]>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<body>
<!-- GENERAL INFO -->
<table>
<tr>
<td align="right">
<j:choose>
<j:when test="${build.result=='SUCCESS'}">
<img src="${rooturl}static/e59dfe28/images/32x32/blue.gif" />
</j:when>
<j:when test="${build.result=='FAILURE'}">
<img src="${rooturl}static/e59dfe28/images/32x32/red.gif" />
</j:when>
<j:otherwise>
<img src="${rooturl}static/e59dfe28/images/32x32/yellow.gif" />
</j:otherwise>
</j:choose>
</td>
<td valign="center"><b style="font-size: 200%;">BUILD ${build.result}</b></td>
</tr>
<tr>
<td>Build URL:</td>
<td><a href="${rooturl}${build.url}">${rooturl}${build.url}</a></td>
</tr>
<tr>
<td>Project:</td>
<td>${project.name}</td>
</tr>
<tr>
<td>Date of build:</td>
<td>${it.timestampString}</td>
</tr>
<tr>
<td>Build duration:</td>
<td>${build.durationString}</td>
</tr>
</table>
<br />
<!-- JUnit TEMPLATE -->
<j:set var="junitResultList" value="${it.JUnitTestResult}" />
<j:if test="${junitResultList.isEmpty()!=true}">
<div>
<h1><a href="${rooturl}${build.url}testReport">JUnit Tests</a></h1>
<table border="1">
<tr>
<th>Package</th>
<th>Duration (sec)</th>
<th>Failed</th>
<th>Failed (diff)</th>
<th>Passed</th>
<th>Passed (diff)</th>
<th>Skipped</th>
<th>Skipped (diff)</th>
<th>Total</th>
<th>Total (diff)</th>
</tr>
<j:forEach var="junitResult" items="${it.JUnitTestResult}">
<j:forEach var="packageResult" items="${junitResult.getChildren()}">
<tr>
<td><tt>${packageResult.getName()}</tt></td>
<td>${packageResult.getDuration()}</td>
<td>${packageResult.getFailCount()}</td>
<td>${packageResult.getFailCount()-packageResult.previousResult.getFailCount()}</td>
<td>${packageResult.getPassCount()}</td>
<td>${packageResult.getPassCount()-packageResult.previousResult.getPassCount()}</td>
<td>${packageResult.getSkipCount()}</td>
<td>${packageResult.getSkipCount()-packageResult.previousResult.getSkipCount()}</td>
<td>
<b>${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()}</b>
</td>
<td>
<b>${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()-packageResult.previousResult.getPassCount()-packageResult.previousResult.getFailCount()-packageResult.previousResult.getSkipCount()}</b>
</td>
</tr>
<!--
<j:forEach var="failed_test" items="${packageResult.getFailedTests()}">
<tr>
<td colspan="5"><tt>${failed_test.getFullName()}</tt></td>
</tr>
</j:forEach>
-->
</j:forEach>
</j:forEach>
</table>
<br />
</div>
</j:if>
</body>
</j:jelly>
@grayaii
Copy link

grayaii commented Feb 18, 2019

Quick Question: Is this is something that goes into the Mail Ext plugin?

@sturman
Copy link

sturman commented Nov 6, 2019

@grayaii you need to copy this file into $JENKINS_HOME/email-templates/template-name.jelly. Then on job configuration page set Default Content field to ${JELLY_SCRIPT,template="template-name"} in Editable Email Notification section

@grayaii
Copy link

grayaii commented Nov 6, 2019

Awesome! Thanks, @sturman, i'll give it a shot!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment