Issue
I have a finally clause in my JenkinsFile which is like
finally{
def script_regex = '${BUILD_LOG_REGEX, regex="^The module", maxMatches=5, showTruncatedLines=false, escapeHtml=true}'
if (script_regex){
emailext to: "[email protected]",
subject: "some subj",
body: script_regex
}
}
I tried using echo(script_regex) but it gives
'${BUILD_LOG_REGEX, regex="^The module", maxMatches=5, showTruncatedLines=false, escapeHtml=true}'
as a string instead of evaluating the regex. Although, it works fine inside exailext. Is there a way to check if this regex returns an empty string? and only send email when the regex returns a matching string. Thanks in advance!
Solution
So after a bit of research, I found that the BUILD_LOG_REGEX
variable is defined by the emailext
plugin. Hence, we cannot use outside it.
Instead we can use something like manager.logContains('<regex>')
and this will check your build log and return a boolean value indicating whether the required string is present or not.
Answered By - Yashvardhan Nanavati