本文介绍了使用 email-ext 插件从 Jenkins 发送关于电子邮件的 Cppcheck 结果/报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Jenkins 构建中的 email-ext 插件在电子邮件中发送 cppcheck 报告.到目前为止,似乎唯一的方法是创建自定义模板——果冻或 groovy.来自这篇文章——我可以将 jenkins 配置为发送带有静态分析报告摘要的电子邮件吗?" -- 看起来我应该能够实例化 CppcheckBuildAction 并使用它的方法,但由于某种原因,它似乎没有实例化(即对象为空).这是我在果冻模板中放入的代码以进行检查:

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>

(我也试过 hudson.plugins.cppcheck.CppcheckBuildAction)而且,果然,我在构建结果电子邮件中得到了 cpppcBuildAction is null!.(我不得不放入if"子句来在果冻上测试这个,因为它不会抛出任何错误,否则.在groovy模板中,我实际上得到了这样的错误消息Exception:javax.script.ScriptException:java.lang.NullPointerException:如果我尝试在对象上调用 getResult 方法,则无法在 null 对象上获取属性getResult").

(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).

是否有人尝试过使用此 email-ext 插件或其他方式通过电子邮件发送 Cppcheck 结果/报告?

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

顺便说一句,还有另一个帖子,其他人正在尝试做我正在尝试做的事情,但该线程似乎并不活跃,或者那里没有真正的互动——"以下果冻脚本模板有什么问题hudson 的 email-ext 插件中的 cppcheck"

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"

推荐答案

你只是使用了错误的命名空间,正确的是:org.jenkinsci.plugins.cppcheck.CppcheckBuildAction.

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>

享受吧!

这篇关于使用 email-ext 插件从 Jenkins 发送关于电子邮件的 Cppcheck 结果/报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 15:39