Thursday, September 5, 2013

How to show stacktrace, standard output and standard error of each test failure in jenkins mail

Email-ext plugin in jenkins allows customizing jenkins build mail at a programmer's will.


Find you jelly script and go to JUnit TEMPLATE portion of the script.

Here's an example how you can change the script to show stacktrace, standard output and standard error.


 <!-- JUnit TEMPLATE -->  
 <j:set var="junitResultList" value="${it.JUnitTestResult}" />  
 <j:if test="${junitResultList.isEmpty()!=true}">  
  <TABLE width="100%">  
   <TR><TD class="bg1" colspan="2"><B>JUnit Tests</B></TD></TR>  
   <j:forEach var="junitResult" items="${it.JUnitTestResult}">  
    <j:forEach var="packageResult" items="${junitResult.getChildren()}">  
     <TR><TD class="bg2" colspan="2"> Name: ${packageResult.getName()} Failed: ${packageResult.getFailCount()} test(s), Passed: ${packageResult.getPassCount()} test(s), Skipped: ${packageResult.getSkipCount()} test(s), Total: ${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()} test(s)</TD></TR>  
     <j:forEach var="failed_test" items="${packageResult.getFailedTests()}">  
      <TR bgcolor="white">  
        <TD class="test_failed" colspan="1">  
          <B><li><h2>Failed: ${failed_test.getFullName()} </h2></li></B>  
        </TD>  
      </TR>  
      <TR>  
         <TD class="test_failed_log" colspan="2">  
          <li><h4>Stacktrace</h4></li><li>${failed_test.getErrorStackTrace()} </li>  
          <li><h4>Standard Output</h4></li><li>${failed_test.getStdout()} </li>  
          <li><h4>Standard Error</h4></li><li>${failed_test.getStderr()} </li>  
        </TD>  
      </TR>  
     </j:forEach>  
    </j:forEach>  
   </j:forEach>  
  </TABLE>  
 <BR/>  
 </j:if>  

You can further change the visual effects through css classes.
To know more options of the ${failed_test} object see CaseResult

No comments:

Post a Comment