同僚は、Jenkins のすべてのビルドにはそれに関連付けられた「アクション」があり、Jenkins プラグインはアクションを介して魔法を行うと私に言いました。で自分のアクションのすべてのアクションを見つけることができましたbuild.getActions()
。LogParserAction
次に、Jenkins Log Parser プラグインによって提供されるアクションを取得するまで、アクションをループしました。
次に、 のソース コードLogParserAction.class
を調べて、メソッドを見つけましたgetErrorLinksFile()
。この方法で、解析されたログのテキストを取得できました。呼び出された同様のメソッドgetWarningLinksFile()
が警告に使用でき、別のメソッドが情報に使用できます。
次に、文字のテキストをループし、\n
いくつかの正規表現を適用して、希望どおりに表示しました。コードの重要な部分を以下に示します。Notepad ++で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>