Skip to content
Advertisement

Jenkins BUILD_LOG_REGEX ( emailext plugin ) does not match across multiple lines ( dotall )

Background

I am trying to use the BUILD_LOG_REGEX environment variable, which is provided by the emailext plugin, to filter a build log. My regular expression is suppose to match everything between the “init:” and “Total time” strings. My regular expression is as follows init:(.*?)Totalstime

The Jenkins emailext code is as follows

JavaScript

The build log is as follows

JavaScript

While this works in almost all online regex testers it does not work in Jenkins. I believe this is related to how the BUILD_LOG_REGEX macro implements dotall but I can’t get it to match across multiple lines. I realize that BUILD_LOG_REGEX is implemented using java.util.regex.Pattern. Can someone assist me with this?

Attempts

I’ve also tried the following regex init:(?s:.*)Totalstime as well as attempting to use the BUILD_LOG_MULTILINE_REGEX ( with both regular expressions ) but both return no matches.

Advertisement

Answer

Solution BUILD_LOG_EXCERPT

I found a roundabout solution using the BUILD_LOG_EXCERPT token. The following code sample gives the results I am looking for using this token.

JavaScript

The unescaped string is ${BUILD_LOG_EXCERPT, start="init:.*", end="Totalstime.*"}

I am still interested in a solution using BUILD_LOG_REGEX or BUILD_LOG_MULTILINE_REGEX

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement