使用电子邮件扩展插件和 jenkins 发送果冻模板时出错

问题描述 投票:0回答:1

我想通过电子邮件发送 cppcheck 报告,但我以前从未使用过电子邮件扩展插件,所以我发现了这个 使用 email-ext 插件从 Jenkins 通过电子邮件发送 Cppcheck 结果/报告,并使用一个漂亮的果冻模板来执行此操作,我还按照文档中的步骤操作,在管道作业中发送我自己的模板,我创建了带有 .jelly 扩展名的模板并将其设置到我的

$JENKINS_HOME\email-templates
中,尽管电子邮件模板文件夹不存在,所以我我不确定是否应该通过安装插件或我缺少的内容来预先创建它。这就是我的舞台

        stage('Mail cppcheck report') {
            steps{
                script{
                    def mailRecipients = "[email protected]"
                    def jobName = currentBuild.fullDisplayName
                    mimeType: 'text/html'
                    emailext body: '''${JELLY_SCRIPT, template="custom"}''',
                    subject: "[Jenkins] ${jobName}",
                    to: "${mailRecipients}" 
                }
            }
        }

这是我想使用的模板,但我不断收到以下错误

 JellyException: Could not parse Jelly script : null
即使电子邮件已发送,电子邮件正文只是上面提到的错误。

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

我还尝试过其他一些模板,没有收到任何错误,但我收到一封空电子邮件,就像这个一样。

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

但是如果我使用默认模板

emailext body: '''${JELLY_SCRIPT, template="html"}'''
它工作正常

jenkins groovy jenkins-pipeline jelly
1个回答
-1
投票

您的问题解决了吗?如果是的话,你能帮我吗?

© www.soinside.com 2019 - 2024. All rights reserved.