Jenkins EMail Reporting

641 views
Skip to first unread message

Bubunia Patra

unread,
Sep 21, 2016, 11:32:28 AM9/21/16
to Jenkins Users
Hi all,

I am looking for some way to email the test results from the Jenkins to the recipients in a nice format After my test executes the console logs are generated in jenkins. I have installed the extended E-mail Plugin for email and configured the smtp server. The test also generates the JUNIT.xml which contains Pass/Fail results but doesn't contain the failure reason which needs to be retrieved from the console logs.

The Email-Plugin emails the results but it is either truncated or not the format I want it. Is there any other plugin I need to use which will retrieve the failure reason from the console log and email the results similar to below:

I want Something like the below in a table  :

TestCase Name |  Status |  Link |  Failure Reason
======================================

Is there a better way or example for Email reporting in Jenkins to suffice my requirement? If so what are the other tools/plugins I should install and the way I can achieve this? I saw the customise email reporting can be achieved through jelly script. Can someone provide me an example jelly script for email reporting ?


I will appreciate if some one can help me in this regard?

Regards
Pradeep

jer...@bodycad.com

unread,
Sep 21, 2016, 1:58:57 PM9/21/16
to Jenkins Users
I known my answer will not be received well by most, but that was the fastest way I could find, I did a Python script with XunitParser module made that a breeze (I can even test it better or use other tools to run them).


Just write to a temporary file using the tmp() folder and then sh or bat the python script and give the output file as argument, output into the wanted format and just read the file into Jenkins pipeline.

All those little Python script have save me hours so far compare to messing around into the Jenkins "cripple" Groovy. Just doing a iteration on list doesn't work as it is suppose too into that Groovy implementation! @NonCPS is a bag of crab so far for me (same function does or doesn't return the same result with or without the @NonCPS, some function I had written where working until some update where I had to add the @NonCPS by updating Jenkins). Having to allow all the operations (map hash, file getAbsolutePath, operator string to string, ...) but can launch a shell or batch operation that can access whatever folder.

May sound harsh on Jenkins, but every new commer have question on how to do simple stuff (this include myself, I'm no different here! the struggle is real, especially for people who did not touch any groovy before and realize they don't really have a full features Groovy engine to play with) because we can't rely on Groovy way of doing those thing, because those way doesn't work most of the time into that implementation or need to be tweak a lots to make them working. Many of those questions are left without answer since nobody really know how to do them properly into that script engine.


jer...@bodycad.com

unread,
Oct 18, 2016, 3:53:55 PM10/18/16
to Jenkins Users
I got some Jelly template working for this. First the jenkins file:

Make sure you collect your unit test results:
step([$class: 'JUnitResultArchiver', testResults: 'TestResult/*.xml']);


Then send the email:
emailext body: '${JELLY_SCRIPT,template="${env.JENKINS_HOME}/email-templates/myTemplateFile.jelly"}', subject: email_subject, to: 'c...@bodycad.com', replyTo: 'jen...@bodycad.com', mimeType: 'text/html'

Take car under Windows the '\\' is not supported into the template path and you need to flip them:
'${JELLY_SCRIPT,template="' + "${env.JENKINS_HOME}/email-templates/myTemplateFile.jelly".replaceAll('[\\\\]','/') + '"}'

Here's the Jelly template that should be saved into Jenkins home folder under email-templates (I removed any style here to simplify the whole thing and removed other parts), you can modify the html to your code:

<?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">
<!-- Header -->
<BODY>
<!-- Unit Test TEMPLATE -->
<TABLE width="100%">
 
<TR>
 
<TD colspan="2"><B>Unit Tests</B></TD>
 
</TR>
 
<j:forEach var="junitResult" items="${it.JUnitTestResult}">
 
<j:forEach var="packageResult" items="${junitResult.getChildren()}">
 
<TR>
 
<TD>Tests Root Name</TD>
 
<TD>${packageResult.getName()}</TD>
 
</TR>
 
<TR>
 
<TD>Tests Counts</TD>
 
<TD>${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()}</TD>
 
</TR>
 
<TR>
 
<TD>Tests Pass</TD>
 
<TD>${packageResult.getPassCount()}</TD>
 
</TR>
 
<TR>
 
<TD>Tests Skip</TD>
 
<TD>${packageResult.getSkipCount()}</TD>
 
</TR>
 
<TR>
 
<TD>Tests Fail</TD>
 
<TD>${packageResult.getFailCount()}</TD>
 
</TR>
 
<j:forEach var="failed_test" items="${packageResult.getFailedTests()}">
 
<TR>
 
<TD colspan="2"><B><li>Failed: ${failed_test.getFullName()} </li></B></TD>
 
</TR>
 
</j:forEach>
 
</j:forEach>
 
</j:forEach>
</TABLE>
<BR/>
<!-- Footer -->
</BODY>
</j:jelly>


Reply all
Reply to author
Forward
0 new messages