Getting error while using BUILD_LOG_REGEX in emailext

294 views
Skip to first unread message

Jyoti singhal

unread,
Jun 23, 2023, 7:13:26 AM6/23/23
to Jenkins Users
Hi All,

I am trying to get one line from build logs and sending in email for that i tied to use BUILD_LOG_REGEX in emailext but its throwing me this error

CodCode:
```
{ emailext (
mimeType: 'text/html',
attachLog: true,
subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}",
body: "${BUILD_LOG_REGEX, regex="Check out job at", maxMatches=2, showTruncatedLines=false}",
to: 'jyoti2xx'
```
Error:
6:10:26  org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
16:10:26  WorkflowScript: 38: unexpected token: BUILD_LOG_REGEX @ line 38, column 15.
16:10:26          body: "${BUILD_LOG_REGEX, regex="Check out job at", maxMatches=2, showTruncatedLines=false}",
16:10:26       


Any idea how to fix this issue?

Thanks,
Jyoti

Alex Earl

unread,
Jun 23, 2023, 8:46:07 AM6/23/23
to Jenkins User Mailing List
When you use double quotes in pipeline, the groovy engine will try and interpolate the variables it sees. You should try using single quotes around the body value.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b64d7b8d-1595-40bd-8096-f88da3e2e81cn%40googlegroups.com.

Jyoti singhal

unread,
Jun 23, 2023, 10:16:13 AM6/23/23
to jenkins...@googlegroups.com
i have tried with Single quotes as well , it takes it as a text and print the complete line as it is.

Thanks,
Jyoti

Alex Earl

unread,
Jun 23, 2023, 12:08:08 PM6/23/23
to jenkins...@googlegroups.com
Can you share your single quote version? I just want to make sure you are doing what I expect.



--

Jyoti singhal

unread,
Jun 23, 2023, 1:09:42 PM6/23/23
to jenkins...@googlegroups.com
Hi Alex,

Apologies from my side. Its working with single quotes now, I was giving the wrong syntax,

Wanted to check one thing right now it's extracting this whole line, Is there any way to just get this link in email? 
image.png

Alex Earl

unread,
Jun 23, 2023, 1:36:07 PM6/23/23
to jenkins...@googlegroups.com
I believe you can use $<num> as the substText parameter, e.g. have a capturing part of your regex and $1 would be the first capture group, $2 would be the second capture group, etc.



--

Jyoti singhal

unread,
Jun 23, 2023, 1:52:26 PM6/23/23
to jenkins...@googlegroups.com
Ok Thank you so much for your help 
This is finally working.
\${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here: "}
Resolution: I have just changed regex and made it check from the start of the line and replace it by using subsText . Its working perfectly now.




Reply all
Reply to author
Forward
0 new messages