Hudson/Jenkins--配置TestNG/JUnit的email-ext email模板

Hudson/Jenkins默认提供了发送邮件的功能,但是比较有局限性。插件Email-ext提供了比较好的email功能。安装好该插件后,可以在$JENKINS_HOME($HUDSON_HOME)/email-templates目录下定义自己的email模板。下面提供一个jelly script基于junit的测试结果生成email的模板,先上email效果图:


该email report风格比较清新,该有的信息都有了,通过的case用绿色标出,失败的case用红色标出,其他的log, 具体的report, 最近build的整体情况的link也都给出。

对应的jelly script(myreport.jelly)如下:

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
 <body style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
  <j:set var="spc" value="&nbsp;&nbsp;" />
  <!-- GENERAL INFO -->
  <table style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
   <tr>
    <td align="right" style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     <j:choose>
      <j:when test="${build.result=='SUCCESS'}">
       <img src="${rooturl}static/e59dfe28/images/32x32/blue.gif">
       </img>
      </j:when>
      <j:when test="${build.result=='FAILURE'}">
       <img src="${rooturl}static/e59dfe28/images/32x32/red.gif">
       </img>
      </j:when>
      <j:otherwise>
       <img src="${rooturl}static/e59dfe28/images/32x32/yellow.gif">
       </img>
      </j:otherwise>
     </j:choose>
    </td>
    <td valign="center" style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     <b style="font-size: 200%;">
      TESTRUN ${build.result}
     </b>
    </td>
   </tr>
   <tr>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     Project:
    </td>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     ${project.name}
    </td>
   </tr>
   <tr>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     Date of run:
    </td>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     ${it.timestampString}
    </td>
   </tr>
   <tr>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     Test duration:
    </td>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     ${build.durationString}
    </td>
   </tr>
   <tr>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     Test report:
    </td>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     <a href="http://xxxxx:8080/view/job/${project.name}/${build.number}/xxx_build_report/">
      xxxxx Test Report
     </a>
    </td>
   </tr>
    <tr>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     Console logs:
    </td>
    <td style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
     <a href="${rooturl}${build.url}console">
      ${rooturl}${build.url}console
     </a>
    </td>
   </tr>
  </table>
  <br />
  
  <div style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
      <j:set var="healthIconSize" value="16x16" />
      <j:set var="healthReports" value="${project.buildHealthReports}" />
      <j:if test="${healthReports!=null}">
	  <b style="font-size: 160%;">Health Report</b>
	  <br />
        <table>
          <tr>
            <th>W</th>
            <th>Description</th>
            <th>Score</th>
          </tr>
          <j:forEach var="healthReport" items="${healthReports}">
            <tr>
              <td>
                <img src="${rooturl}${healthReport.getIconUrl(healthIconSize)}" />
              </td>
              <td>${healthReport.description}</td>
              <td>${healthReport.score}</td>
            </tr>
          </j:forEach>
        </table>
        <br />
      </j:if>
    </div>
	

  <j:set var="junitResultList" value="${it.JUnitTestResult}" />
    <j:if test="${junitResultList.isEmpty()!=true}">
	  <div style="font-family: Verdana, Helvetica, sans serif; font-size: 11px; color: black">
        <b style="font-size: 160%;">Summary Report</b>
		<br />
        <table style="border: 1px solid black; border-collapse:collapse;">
          <tr>
            <th style="border: 1px solid black; border-collapse:collapse;">Package</th>
            <th style="border: 1px solid black; border-collapse:collapse;">Failed</th>
            <th style="border: 1px solid black; border-collapse:collapse;">Passed</th>
            <th style="border: 1px solid black; border-collapse:collapse;">Skipped</th>
            <th style="border: 1px solid black; border-collapse:collapse;">Total</th>
          </tr>
          <j:forEach var="junitResult" items="${it.JUnitTestResult}">
            <j:forEach var="packageResult" items="${junitResult.getChildren()}">
              <tr>
                <td style="border: 1px solid black; border-collapse:collapse;">
                  <tt>${packageResult.getName()}</tt>
                </td>
                <td style="border: 1px solid black;border-collapse:collapse; color:red;">${packageResult.getFailCount()}</td>
                <td style="border: 1px solid black;border-collapse:collapse; color:blue;">${packageResult.getPassCount()}</td>
                <td style="border: 1px solid black;border-collapse:collapse; color:grey;">${packageResult.getSkipCount()}</td>
                <td style="border: 1px solid black;border-collapse:collapse;">
                  <b>${packageResult.getPassCount()+packageResult.getFailCount()+packageResult.getSkipCount()}</b>
                </td>
              </tr>
			  <j:forEach var="passed_test" items="${packageResult.getPassedTests()}">
                <tr>
                  <td style="color:green;" colspan="5">
                    <tt>${passed_test.getFullName()}</tt>
                  </td>
                </tr>
              </j:forEach>
              <j:forEach var="failed_test" items="${packageResult.getFailedTests()}">
                <tr>
                  <td style="color:red;" colspan="5">
                    <tt>${failed_test.getFullName()}</tt>
                  </td>
                </tr>
              </j:forEach>
            </j:forEach>
          </j:forEach>
        </table>
		<br />
		<div>Note: See attachment also for summary report broken down by classes/methods.</div>
        <br />
      </div>
    </j:if>
 </body>
</j:jelly>

值得注意的是,在hudson/jenkins中,必须设置Publis JUnit test result report,同时,在editable email notification的Default Content中填入${JELLY_SCRIPT,template="myreport"},如下图所示:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值