3

I'd like to send an email after a build completes with some data from the reports that are run (PMD, Checkstyle, Findbugs, Cobertura) such as number of issues, new issues, coverage etc.

Is this possible?

blank
  • 17,852
  • 20
  • 105
  • 159

3 Answers3

2
<j:set var="pmd" value="${it.getAction('hudson.plugins.pmd.PmdResultAction')}" />
<j:if test="${pmd.isEmpty()!=true}">
   <TABLE width="100%">
       <TR><TD colspan="2" class="bg1"><B>PMD Result</B></TD></TR>
      <tr><td>Total:</td><td>${pmd.result.numberOfWarnings}</td></tr>
      <tr><td>High:</td><td>${pmd.result.getNumberOfAnnotations('HIGH')}</td></tr>
      <tr><td>Normal:</td><td>${pmd.result.getNumberOfAnnotations('NORMAL')}</td></tr>
      <tr><td>Low:</td><td>${pmd.result.getNumberOfAnnotations('LOW')}</td></tr>
      <tr><td>New:</td><td>${pmd.result.numberOfNewWarnings}</td></tr>
      <tr><td>Fixed:</td><td>${pmd.result.numberOfFixedWarnings}</td></tr>
      <tr><td colspan="2"><a href="${rooturl}${build.url}/pmdResult/">View Report</a></td></tr>
   </TABLE >    
<BR/>
</j:if>

Have a try! More check my gist here: https://gist.github.com/yangboz/9204868

Knight.zhou
  • 29
  • 1
  • 10
  • where can I see the methods available for any given plugin (i.e. cppcheck) so I can set my own template with the information I need? – Jesus Fernandez Apr 09 '21 at 10:28
1

I've managed to get some data using the email-ext plugin. You need to include a jelly file in the email sent like this:

${JELLY_SCRIPT, template="html"}

There is a default template (html.jelly) which includes junit and Cobertura results which I've modified by adding something like this:

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
 ...
 <j:set var="fb" value="${it.getAction('hudson.plugins.findbugs.FindBugsResultAction')}" />
  <table width="100%">
   <tr><td colspan="2"><b>Findbugs Result</b></td></tr>
   <tr><td>Total:</td><td>${fb.result.numberOfWarnings}</td></tr>
   <tr><td>Fixed:</td><td>${fb.result.numberOfFixedWarnings}</td></tr>
   <tr><td>New:</td><td>${fb.result.numberOfNewWarnings}</td></tr>
   <tr><td colspan="2"><a href="${rooturl}${build.url}/findbugs">View Report</a></td></tr>
</table>
 ...
</j:jelly>

For PMD and CheckStyle you can do something similar with:

<j:set var="pmd" value="${it.getAction('hudson.plugins.pmd.PmdResultAction')}" />
<j:set var="cs" value="${it.getAction('hudson.plugins.checkstyle.CheckStyleResultAction')}" />

I've not yet found a way to include the low/medium/high priority figures for the results.

blank
  • 17,852
  • 20
  • 105
  • 159
  • Does this work for you? "${it.getAction('hudson.plugins.findbugs.FindBugsResultAction')}".Doesnt seem to work for me. – crankparty Apr 03 '12 at 06:03
  • I've updated the answer with the exact markup from the working jelly file - the it.getAction bit is the same. – blank Apr 03 '12 at 07:50
  • Thank you. I will try with the new config. – crankparty Apr 03 '12 at 10:17
  • Remember, you have to actually generate the findbugs report using ant or maven, this will only pick up the results of that report. – blank Apr 03 '12 at 10:21
  • 1
    Yes yes. Reports are generated as part of maven build. – crankparty Apr 03 '12 at 10:41
  • As a matter of fact, there is a ````static-analysis.jelly```` for specifically this purpose. You might want to try that as well. Its available at ````$JENKINS_HOME/plugins/email-ext/WEB-INF/classes/hudson/plugins/emailext/templates```` – divinedragon May 07 '13 at 15:34
0

In my case worked https://stackoverflow.com/a/22008267/1688570

For exact Action names look in \Jenkins\jobs\fispp-all-master\builds\${buildNumber}\build.xml file. I.e. I had to use hudson.plugins.findbugs.FindBugsMavenResultAction to show correct results.

Community
  • 1
  • 1
TouDick
  • 1,262
  • 12
  • 18