Email Extension Plugin - can't get BUILD_LOG_EXCERPT to work

北城以北 提交于 2019-12-23 11:46:10

问题


No matter what I put in BUILD_LOG_EXCERPT, all I get is an email with an empty body, thus could use some assistance.

I have a java program that writes to console. Snippet of Jenkins console output looks like this:

...
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building project1 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ project1 ---
Parameters provided: SG, 100, 1000
query: select COUNT(*) from table1 where col1 = ? and col2 = ? and col3 = ?
Rows in table: 5776
Threshold: 100
Rows returned above threshold, skipping dpan generation batch file.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.125 s
[INFO] Finished at: 2016-02-08T09:31:37-08:00
[INFO] Final Memory: 8M/245M
...

In the Jenkins job, I create a Post Build step, and put the following line in Default Content:

${BUILD_LOG_EXCERPT, start="\\b(Parameters)\\b", end="\\b(Threshold)\\b"}

When I trigger the job, all i get is an empty email. However if I add

${BUILD_LOG, maxLines=9999, escapeHtml=false}

then i get the full console output in the email. Any ideas? I am using version 2.40.3 of the plugin.


回答1:


Looks like your regex is failing to find any matches, so you aren't getting any lines of the log. This is because the BUILD_LOG_EXCERPT variable uses java.util.regex.Pattern.Matcher.matches() to match a regex - and this will only return True if the entire string matches (referenced in this SO question). The log parser is running line-by-line, so it's testing your entire line against your regex and failing (since there are characters after "Parameters").

If you're looking for a string that starts with Parameters but may have characters after it, you can match to

"\\b(Parameters)\\b(?s).*"

which will match "Parameters" and any arbitrary string after it.




回答2:


BUILD_LOG_EXCERPT in email-ext follows a very simple regex match using start and end. got it working by using two echo statements i.e one at the start from where i wanted the piece of console log and one at the end position of the log you wanted in email.

example :

In Build step :

echo Start
<your build commands>
echo End

In Default section of email-ext use the below line to get it working :

${BUILD_LOG_EXCERPT, start="^Start", end="^End"}

if your using a html email output you can use below line to align output in email

<pre>${BUILD_LOG_EXCERPT, start="^Start", end="^End"}</pre>

you can tweak and get it working , Hope it works for you as it did for me .



来源:https://stackoverflow.com/questions/35276096/email-extension-plugin-cant-get-build-log-excerpt-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!