2014-05-07 65 views
2

擴展電子郵件通知的「默認內容」,如下設置和默認的內容類型發送常規代碼是「HTML(text/html的)」:詹金斯電子郵件分機插件在電子郵件正文

<html> 
<body> 
<% 
    if(build.testResultAction) { 
     def testResult = build.testResultAction 
     def testCount = String.format("%.2f",(testResult.totalCount)) 
     def testPassed = String.format("%.2f",()) 
     def testFailed = String.format("%.2f",(testResult.result.failCount)) 
     def testSkipped = String.format("%.2f",()) 
     def buildDuration = String.format("%.2f",(testResult.result.duration)) 
    } 
%> 
Hi All,<br><br> 

The execution of the Automation suite has been completed and the results are as below.<br><br> 

<b><u>Configuration :</u></b><br> 
Project Name : $JOB_NAME<br> 
Test Server URL : $Test_Server_URL<br> 
Group Name : $Group_Name<br><br> 

<b><u>Execution Results :</u></b><br> 
Status : <font color="blue">$BUILD_STATUS</font><br> 
Tests run : $testCount<br> 
Failures : $testFailed<br> 
Errors : 0<br> 
Skipped : 0<br> 
Total time : $buildDuration<br> 
Finished at: Tue May 06 17:12:19 IST 2014<br> 
Build URL : $BUILD_URL<br><br> 

The HTML version of the automation results and the log file is attached with this e-mail for your reference.<br><br> 

Regards,<br> 
Jenkins CI Tool 
</body> 
</html> 

但是,報告電子郵件在其主體中具有groovy代碼本身,而不是預期值。

+0

順便說一句,如果這個腳本放在test.groovy下電子郵件-EXT插件用@Akos Bannerth答案作爲運行按照以下說明,然後我們上線7和9的異常。 。遺漏了什麼 ? msgstr「」「在模板呈現過程中引發異常:無法解析模板腳本(您的模板可能包含錯誤或嘗試使用當前不支持的表達式):startup failed:SimpleTemplateScript1.groovy:7:unexpected token:)@ line 7,column 48. assed = String.format(「%。2f」,())^ 1「」「 – gaoithe

回答

6

檢查emai-ext plugin的維基頁面有關使用腳本內容,有沒有描述的步驟:

  1. 把你的Groovy腳本到一個文件
  2. 將它放在詹金斯大師,JENKINS_HOME/email-templates/
  3. 下在電子郵件配置中,使用腳本標記替換內容:${SCRIPT, template="name-of-template"}
0

此處僅供參考, @Vel Ganesh修正了語法。 這很粗糙,但與詹金斯合作2.7.4 2017年1月)。

按照@Akos Bannerth的答案。 將groovy腳本放入test.groovy文件中。

<html> 
<body> 
<% 

    import hudson.model.* 

    def build = Thread.currentThread().executable 
    def buildNumber = build.number 
    def buildNameJ = build.getDisplayName() 

    def testCount = "0" 
    def testPassed = "0" 
    def testFailed = "0" 
    def testSkipped = "0" 
    def buildDuration = "0" 
    if(build.testResultAction) { 
     def testResult = build.testResultAction 
     testCount = String.format("%d",(testResult.totalCount)) 
     testPassed = String.format("%d",(testResult.result.passCount)) 
     testFailed = String.format("%d",(testResult.result.failCount)) 
     testSkipped = String.format("%d",(testResult.result.skipCount)) 
     buildDuration = String.format("%.2f",(testResult.result.duration)) 
    } 

    def workspace = build.getEnvVars()["WORKSPACE"] 
    def buildName = build.getEnvVars()["JOB_NAME"] 
    def BUILD_STATUS = build.getEnvVars()["BUILD_STATUS"] 
    def BUILD_URL = build.getEnvVars()["BUILD_URL"] 
    def Test_Server_URL = build.getEnvVars()["Test_Server_URL"] 
    def Group_Name = build.getEnvVars()["Group_Name"] 
%> 

Summary test report <br><br> 

<b><u>Configuration :</u></b><br> 
Workspace : $workspace<br> 
Project Name : $buildName $buildNameJ<br> 
Test Server URL : $Test_Server_URL<br> 
Group Name : $Group_Name<br><br> 

<b><u>Execution Results :</u></b><br> 
Status : <font color="blue">$BUILD_STATUS</font><br> 
Tests run : $testCount<br> 
Failures : $testFailed<br> 
Errors : . . . TODO . . . <br> 
Skipped : $testSkipped<br> 
Total time : $buildDuration<br> 
Finished at: Tue May 06 17:12:19 IST 2014<br> 
Build URL : $BUILD_URL<br><br> 

test.groovy 

</body> 
</html> 
相關問題