1

I'm trying to send cppcheck report on an email using email-ext plugin from a Jenkins build. So far, only way seems to be by creating a custom template -- jelly or groovy. From this post -- "Can I configure jenkins to send an email with a static analysis report summary?" -- it looks like I should be able to instantiate CppcheckBuildAction and use its methods but for some reason, it doesn't seem to instantiate (ie. the object is null). Here's the code I've put in the jelly template to check this:

<j:set var="cppcBuildAction" value="${it.getAction('com.thalesgroup.hudson.plugins.cppcheck.CppcheckBuildAction')}"/>
<j:if test="${cppcBuildAction==null}">
<p><i>cppcBuildAction is null!</i></p>
</j:if>

(I also tried hudson.plugins.cppcheck.CppcheckBuildAction) And, sure enough, I get cpppcBuildAction is null! in the build result email. (I had to put in "if" clause to test this on jelly because it doesn't throw out any error, otherwise. In groovy template, I actually get the error message like "Exception: javax.script.ScriptException: java.lang.NullPointerException: Cannot get property 'getResult' on null object" if I try to call getResult method on the object).

Has anybody tried sending Cppcheck result/report over email using this email-ext plugin or otherwise?

BTW, there is another post where someone else is trying to do what I'm trying to do but the thread doesn't seem to be active or there's no real interaction going on there -- "What's wrong with following jelly script template for cppcheck in email-ext plugin of hudson"

Community
  • 1
  • 1
wonderer
  • 11
  • 2
  • Debug using this Groovy code - <% build.getActions().each() { action -> %><%=action.getClass().getName()%><% } %> – Josh Unger Feb 28 '13 at 00:04

2 Answers2

2

You just use wrong namespace, right one is: org.jenkinsci.plugins.cppcheck.CppcheckBuildAction.

For debugging you could use the following code:

<j:forEach var="a" items="${build.getActions()}">
action: ${a.getClass().getName()}
<BR/>
</j:forEach>

And finally the following code works for me:

<!-- CppCheck TEMPLATE -->

<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
    <j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
    <j:if test="${cppcheckResult!=null}">
        <TABLE width="100%">
            <TR><TD class="bg1" colspan="2"><B>CPPCHECK RESULT</B></TD></TR>
            <TR bgcolor="white"><TD class="test_failed" colspan="2"><B><li><a href="${rooturl}${build.url}cppcheckResult">Found: ${cppcheckResult.report.getNumberTotal()}</a></li></B></TD></TR>
        </TABLE>
        <BR/>
    </j:if>
</j:if>

Enjoy!

  • 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
0

I found myself wanting to do the same thing: Send a email-ext email with the results of the cppcheck analysis.

This jelly script works with what Sergey provided above and makes a table similar to the one found in the results page.

Hopefully this will save someone an hour somewhere.

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
  <html>
    <j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
      <j:if test="${cppcheckAction!=null}">
    <j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
    <j:if test="${cppcheckResult!=null}">
      <h2>Summary</h2>
        <style type="text/css">
    #cppcheckStatistics { width: auto; }
    #cppcheckStatistics .number { text-align: right; }
        </style>
        <table class="pane sortable" id="cppcheckStatistics">
          <thead>
            <tr>
              <td class="pane-header">Severity</td>
              <td class="pane-header">Count</td>
              <td class="pane-header">Delta</td>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td class="pane">Error</td>
              <td class="pane number">${cppcheckResult.statistics.getNumberErrorSeverity()}</td>
              <td class="pane number">${cppcheckResult.getDiff().getNumberErrorSeverity()}</td>
            </tr>
            <tr>
              <td class="pane">Warning</td>
              <td class="pane number">${cppcheckResult.statistics.getNumberWarningSeverity()}</td>
              <td class="pane number">${cppcheckResult.getDiff().getNumberWarningSeverity()}</td>
            </tr>
            <tr>
              <td class="pane">Style</td>
              <td class="pane number">${cppcheckResult.statistics.getNumberStyleSeverity()}</td>
              <td class="pane number">${cppcheckResult.getDiff().getNumberStyleSeverity()}</td>
            </tr>
            <tr>
              <td class="pane">Performance</td>
              <td class="pane number">${cppcheckResult.statistics.getNumberPerformanceSeverity()}</td>
              <td class="pane number">${cppcheckResult.getDiff().getNumberPerformanceSeverity()}</td>
            </tr>
            <tr>
              <td class="pane">Portability</td>
              <td class="pane number">${cppcheckResult.statistics.getNumberPortabilitySeverity()}</td>
              <td class="pane number">${cppcheckResult.getDiff().getNumberPortabilitySeverity()}</td>
            </tr>
            <tr>
              <td class="pane">Information</td>
              <td class="pane number">${cppcheckResult.statistics.getNumberInformationSeverity()}</td>
              <td class="pane number">${cppcheckResult.getDiff().getNumberInformationSeverity()}</td>
            </tr>
            <tr>
              <td class="pane">No category</td>
              <td class="pane number">${cppcheckResult.statistics.getNumberNoCategorySeverity()}</td>
              <td class="pane number">${cppcheckResult.getDiff().getNumberNoCategorySeverity()}</td>
            </tr>
          </tbody>
          <tfoot>
            <tr class="sortbottom">
              <td class="pane-header">Total</td>
              <td class="pane-header number"><B><a href="${rooturl}${build.url}cppcheckResult">${cppcheckResult.report.getNumberTotal()}</a></B></td>
              <td class="pane-header number"><B><a href="${rooturl}${build.url}cppcheckResult/source.all/?before=5&amp;after=5&amp;states=new">${cppcheckResult.getDiff().getNumberTotal()}</a></B></td>
            </tr>
          </tfoot>
        </table>
      </j:if>
    </j:if>
  </html>
</j:jelly>
jpadams
  • 119
  • 1
  • 7
  • from where you get this code file?or have you created this code? –  Sep 15 '16 at 11:39
  • @user6521303 this code should come from the cppcheck jenkins plugin source code – Xiao Nov 01 '16 at 07:27
  • I know this is an old post but I am trying the same ( to send cppcheck reports by email) and I found this template I wanted to try, I just created a file.template in `$JENKINS_HOME\email-templates` and then added a stage like this to my pipeline `emailext( mimeType: 'text/html', body: '${SCRIPT, template="my_email.template"}', subject: "[Jenkins] ${jobName}", to: "${mailRecipients}")` but instead of receiving the template I receive a the string `${SCRIPT, template="my_email.template"}` – Jesus Fernandez Apr 07 '21 at 14:41
  • For Jelly templates I think you'll want to use ${JELLY_SCRIPT,template="blah"}. More info here: https://plugins.jenkins.io/email-ext/ – jpadams Apr 07 '21 at 17:39
  • sorry I just copy pasted wrong I am using `${JELLY_SCRIPT,template="blah"}` yet I receive an empty email if using your template, if using the default template by `${JELLY_SCRIPT,template="html"}` or using the template from the official docu here https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/static-analysis.jelly I get a right email, any hints? – Jesus Fernandez Apr 08 '21 at 12:31
  • Are you replacing 'blah' with the name of the file in your email-templates folder without the '.jelly' extension? – jpadams Apr 09 '21 at 00:14
  • yes I made it work at the end but 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:29