2012-01-03 77 views
10

我正在使用兩個Jenkins插件,Email-ExtLog Parser。我擁有Log Parser插件的正則表達式,我希望它們如何,並且我希望在生成後發送給用戶的電子郵件中包含Log Parser插件的輸出。在郵件中發送解析的控制檯輸出

Email-Ext插件可以訪問控制檯輸出,我可以重寫電子郵件中控制檯輸出的正則表達式,但由於Log Parser插件已經完成了艱苦的工作,我希望有一些方法我可以將其輸出結果放入電子郵件中。

有沒有人知道任何方式(如詹金斯環境變量),這可以做到?

回答

0

如果您能夠拉動日誌並寫入文件。 您可以使用Email-Ext將該文件作爲附件附加到您的電子郵件。

+0

它是否與電子郵件-Ext也可以內聯日誌?在文檔中找不到這個?也許以某種方式通過腳本? – Strinder 2016-04-08 08:47:29

+1

找到解決方案:只需將

${BUILD_LOG, maxLines=9999, escapeHtml=false}
添加到內容區 – Strinder 2016-04-08 08:52:51

1

一位同事告訴我,詹金斯的每一個構建都有與之相關的「行爲」,並且詹金斯插件通過行動來實現他們的魔力。我能夠通過build.getActions()找到我的所有動作。然後我循環行動,直到我得到LogParserAction這是Jenkins Log Parser插件提供的操作。

然後,我查看了LogParserAction.class的源代碼以找到方法getErrorLinksFile()。通過這種方法,我能夠獲得解析日誌的文本。類似的方法稱爲getWarningLinksFile()可用於警告,另一種可用於信息。

然後我打開\n字符的文字,並應用了一些正則表達式使其看起來如何。代碼的重要部分如下。看起來更好,如果你在記事本中查看它爲HTML +

%> 
    <TABLE width="100%"> 
     <TR> 
      <TD class="bg1" colspan="2">ERRORS</TD> 
     </TR> 
<% 
    def publisher = null 
    for(iter in project.getPublishersList()){ 
     if(iter.getDescriptor().getDisplayName().equals("Editable Email Notification")){ 
      publisher = iter 
      break 
     } 
    } 
    if(publisher != null){ 
     def logParserResult 
     //Get the LogParserAction from Jenkins 
     for(action in build.getActions()){ 
      if(action.toString().contains("LogParserAction")){ 
       //Get the LogParserResult from the LogParserAction 
       logParserResult = action.getResult() 
       break 
      } 
     } 

     //Get the ErrorLinksFile from the LogParserResult 
     def errorLinksFile = new File(logParserResult.getErrorLinksFile()) 

     //Rewrite the URL so it directs to something useful 
     pattern = ~/<a.*?><font.*?>/ 
     def errorList = [] 
     for(line in errorLinksFile.getText().split("\n")){ 
      //All errors have a link, so this makes sure no superfluous text is displayed 
      if(!line.contains("href")){ 
       continue 
      } 
      errorList.add(line.replaceAll(pattern, "<a href="+ rooturl + build.url + "parsed_console/?\">").minus("</font>")) 
     } 
%> 
     <TR> 
      <TD class="bg2" colspan="2">Total : ${errorList.count{it}} error(s)</TD> 
     </TR> 
<% 
     for(error in errorList){ 
%> 
     <TR> 
      <TD class="errors" colspan="2">${error}</TD> 
     </TR> 
<% 
     } 
%> 
    </TABLE> 
+3

有關使用更多規範Groovy代碼的想法,請參閱[本要點](https://gist.github.com/1566181);這是未經測試,但非常接近。這似乎是一個恥辱,寫這樣的Groovy :( – 2012-01-05 17:14:50

+1

哈哈,謝謝...卡住爪哇世界我想:) – ubiquibacon 2012-01-05 17:24:33