Email Extension Plugin - can't get BUILD_LOG_EXCERPT to work
Asked Answered
B

2

5

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.

Baneful answered 8/2, 2016 at 17:53 Comment(0)
B
6

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.

Brandes answered 12/2, 2016 at 7:36 Comment(2)
The regex works fine on a regex editor, but just not on this particular output. The java program is writing to console via System.out.println(). Is the output of the app formatted in such a way that would cause regex to not work?Baneful
I was wrong about how the regex was being parsed - updated my answer :)Brandes
B
6

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 .

Blockish answered 12/2, 2016 at 7:35 Comment(1)
Is there an option to find a line starting with a special word?Guadalcanal
B
6

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.

Brandes answered 12/2, 2016 at 7:36 Comment(2)
The regex works fine on a regex editor, but just not on this particular output. The java program is writing to console via System.out.println(). Is the output of the app formatted in such a way that would cause regex to not work?Baneful
I was wrong about how the regex was being parsed - updated my answer :)Brandes

© 2022 - 2024 — McMap. All rights reserved.