我正在尝试使用来自Jenkins构建的email-ext插件发送电子邮件的 cppcheck 报告。到目前为止,唯一的方法似乎是创建一个自定义模板 - 果冻或groovy。从这篇文章 - “Can I configure jenkins to send an email with a static analysis report summary?” - 看起来我应该能够实例化CppcheckBuildAction并使用它的方法,但由于某种原因,它似乎没有实例化(即对象是null)。这是我在果冻模板中放入的代码来检查:
<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>
(我也试过hudson.plugins.cppcheck.CppcheckBuildAction) 而且,当然,我在构建结果电子邮件中得到 cpppcBuildAction为空!。 (我不得不在“if”子句中输入测试这个,因为它不会抛出任何错误,否则。在groovy模板中,我实际上得到的错误信息如“Exception:javax.script.ScriptException:java.lang .NullPointerException:如果我尝试在对象上调用getResult方法,则无法在null对象上获取属性'getResult'。
是否有人尝试使用此电子邮件插件或其他方式通过电子邮件发送Cppcheck结果/报告?
顺便说一下,还有另外一个帖子,其他人正试图做我想做的事情,但线程似乎没有活跃,或者那里没有真正的互动 - “What's wrong with following jelly script template for cppcheck in email-ext plugin of hudson”答案 0 :(得分:1)
你只使用错误的命名空间,正确的是:org.jenkinsci.plugins.cppcheck.CppcheckBuildAction。
对于调试,您可以使用以下代码:
<j:forEach var="a" items="${build.getActions()}">
action: ${a.getClass().getName()}
<BR/>
</j:forEach>
最后,以下代码适用于我:
<!-- 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>
享受!
答案 1 :(得分:0)
我发现自己想做同样的事情:发送一封包含cppcheck分析结果的电子邮件电子邮件。
这个果冻脚本与谢尔盖上面提供的内容一起使用,并创建了一个类似于结果页面中的表格。
希望这会在某个地方节省一个小时。
<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&after=5&states=new">${cppcheckResult.getDiff().getNumberTotal()}</a></B></td>
</tr>
</tfoot>
</table>
</j:if>
</j:if>
</html>
</j:jelly>