Hi,
I can give you my template I used to have when non pipeline (haven't tested 
it into the pipeline, I went Jelly). Here's the code for JUnit part
<!-- JUnit TEMPLATE -->
<% def junitResultList = it.JUnitTestResult
if (junitResultList.size() > 0) { %>
  <TABLE width="100%">
    <TR style="${style_tr}">
<TD style="${style_bg1}" colspan="2"><B>JUnit Tests</B></TD>
</TR>
    <% it.JUnitTestResult.each{ junitResult ->
      junitResult.getChildren().each { packageResult -> %>
        <TR style="${style_tr}">
<TD style="${style_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>
        <% packageResult.getFailedTests().each{ failed_test -> %>
<TR style="${style_tr}">
<TD style="${style_bg3}${style_failure}" colspan="2"><B><li>Failed: 
${failed_test.getFullName()} </li></B></TD>
</TR>
        <% }
      }
    }
} %>
  </TABLE>

For the Jelly I end up with the following:
<!-- XUnit 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 style=" ${style_success}">${packageResult.getPassCount()}</TD>
</TR>
<TR>
<TD>Tests Skip</TD>
<TD style="${style_unstable}">${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/>



On Thursday, November 24, 2016 at 5:55:44 AM UTC-5, Bubunia Patra wrote:
>
>
>
> On Thursday, November 24, 2016 at 11:45:16 AM UTC+5:30, Baptiste Mathus 
> wrote:
>>
>> So what does not work? What is the error?
>>
> Code : I want to print TestName after parsing the JUNIT xml. I want to 
> parse the jUNIT and fill the table,
>
> <table cellspacing="0" cellpadding="2" border="1">
> <thead>
>  <tr bgcolor="#F3F3F3">
>   <td class="header">Test Name
>   <% 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) { %>
>  <TABLE width="100%">
>  <TR><TD class="bg1" 
> colspan="2"><B>${junitResultList.first().displayName}</B></TD></TR> 
>   <% junitResultList.each{
>   junitResult -> %>
>      <% junitResult.getChildren().each { packageResult -> %>
>         <TR><TD class="bg2" colspan="2"> ${packageResult.getName()} } 
>  </TD></TR>
> <% } %>
>   </td>
>   <td class="header">Test Status</td>
>   <td class="header">Pass</td>
>   <td class="header">Fail</td>
>   <td class="header">Total</td>
>  </tr>
> </thead>
> </table> 
>
> It fails with Parsing Error. The error message is also not clear. 
>
> Exception raised during template rendering: Failed to parse template 
> script (your template may contain an error or be trying to use expressions 
> not currently supported): startup failed: SimpleTemplateScript61.groovy: 
> 424: expecting '}', found '' @ line 424, column 40. /* Generated by 
> SimpleTemplateEngine */ ^ 1 error groovy.lang.GroovyRuntimeException: 
> Failed to parse template script (your template may contain an error or be 
> trying to use expressions not currently supported): startup failed: 
> SimpleTemplateScript61.groovy: 424: expecting '}', found '' @ line 424, 
> column 40. /* Generated by SimpleTemplateEngine */ ^ 1 error at 
> groovy.text.SimpleTemplateEngine.createTemplate(SimpleTemplateEngine.java:125)
>  
> at groovy.text.TemplateEngine.createTemplate(TemplateEngine.java:38) at 
> hudson.plugins.emailext.plugins.content.ScriptContent.renderTemplate(ScriptContent.java:128)
>  
> at 
> hudson.plugins.emailext.plugins.content.ScriptContent.evaluate(ScriptContent.java:69)
>  
> at 
> hudson.plugins.emailext.EmailExtTemplateAction.renderTemplate(EmailExtTemplateAction.java:132)
>  
> at sun.reflect.GeneratedMethodAccessor1346.invoke(Unknown Source) at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at 
> java.lang.reflect.Method.invoke(Unknown Source) at 
> org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298) at 
> org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161) at 
> org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96) 
> at 
>
>
> Is there a document I can refer for syntax to while writing groovy 
> template script?
>
> Regards
> Pradeep
>  
>
>> Le 24 nov. 2016 6:21 AM, "Bubunia Patra" <[email protected]> a écrit :
>>
>> Hi all,
>>
>> I am new to groovy and the syntax is very confusing and error prone and 
>> written a template to work with Email-Extn plugin. I want to add the test 
>> result in the tabular format as below. Can anyone help me in this regard?
>>
>> Regards
>> Pradeep
>>
>> For exp if 1 test executed then i want a table in the email-body as 
>> follows: 
>>
>> TestName | Test Status | Pass | Fail | Total
>>      
>> abc          |  Pass          |  1     |  0 |  1
>>
>> <table cellspacing="0" cellpadding="2" border="1">
>> <thead>
>>  <tr bgcolor="#F3F3F3">
>>   <td class="header">Test Name</td>
>>   <td class="header">Test Status</td>
>>   <td class="header">Pass</td>
>>   <td class="header">Fail</td>
>>   <td class="header">Total</td>
>>  </tr>
>> </thead>
>> </table>
>>
>> <% 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) { %>
>>  <TABLE width="100%">
>>  <TR><TD class="bg1" 
>> colspan="2"><B>${junitResultList.first().displayName}</B></TD></TR>
>>  <% junitResultList.each{
>>   junitResult -> %>
>>      <% junitResult.getChildren().each { packageResult -> %>
>>         <TR><TD class="bg2" colspan="2"> ${packageResult.getName()} 
>> ${packageResult.getFailCount()},${packageResult.getPassCount()},${packageResult.getSkipCount()},${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()}</TD></TR>
>>         <% packageResult.getFailedTests().each{ failed_test -> %>
>>           <TR bgcolor="white"><TD class="test_failed" 
>> colspan="2"><B><li>Failed: ${failed_test.getFullName()} </li></B></TD></TR>
>>         <% }
>>       }
>>  } %>
>>  </TABLE>
>>  <BR/>
>> <%
>> } %>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Jenkins Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jenkinsci-users/cc06fcf9-7be4-40ad-8437-a5da816206b7%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/jenkinsci-users/cc06fcf9-7be4-40ad-8437-a5da816206b7%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/bc82f7ad-0e08-465f-9931-92cc174927e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to