Search code examples
emailjenkinsjenkins-pluginsemail-ext

Email Extension Plugin - can't get BUILD_LOG_EXCERPT to work


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.


Solution

  • 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.