简体   繁体   中英

Sending Cppcheck result/report on email from Jenkins using email-ext plugin

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 "

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!

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM