I have a JenkinsFile where I am using emailext to send mail for the automation results:
def subject = "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"
def color = currentBuild.currentResult == 'FAILURE' ? 'red' : 'green'
emailext (
mimeType: 'text/html',
attachLog: true,
subject: subject,
body:
"""
<h3><font color='${color}'>${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} </h3></font><br> More info at: ${env.BUILD_URL}<br><br>
Total test case: \${TEST_COUNTS,var="total"} <br>
Pass: \${TEST_COUNTS,var="pass"} <br>
Fail: \${TEST_COUNTS,var="fail"} <br>
<br>
${htmlTable}
<br>
\${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here:"}<br><br>
<p>Click the link below to view the report:</p><a href="${env.BUILD_URL}/QmateReport">View Report</a>
""",
to: '[email protected]'
)
For this line \${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here:"}<br><br>
I am getting multiple matches and it's all coming in an unformatted way, in one line.
Is there a way to get those matched records in email in NextLine
This is the result we are getting in email.

I would like to see this in NextLine like
Access the Recording Here:
Access the Recording Here:
I tried to use the below two points
- Use /n in substText
\${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here: \n"}<br><be>
- Use Actual Newline Character: Instead of \n, try using an actual newline character within the string. You can achieve this by pressing Enter after the colon and continuing the string on the next line. For example:
\${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here:
"}
But nothing is working.
Preamble
The
BUILD_LOG_REGEXmacro has always supported aaddNewlineattribute with a default value oftruesince it was introduced in the token-macro-plugin 2.0-beta release. It should add a new line character at the end of each match by default.If the provided solutions do not work I would request the following:
List of Solutions
I would recommend trying two different solutions.
addNewline="true"attribute to the BUILD_LOG_REGEX macroaddNewline="true"andmatchedLineHtmlStyleattributes (matchedLineHtmlStyleallows you to provide inline CSS styling on expression matches )If these two solution's don't work you may be able to add a
println()directly after the code that prints Check out job at to your build log, then addlinesAfter="1"as an attribute to the BUILD_LOG_REGEX macro. However, I was not able to get this to work.Additionally, I've had some luck wrapping BUILD_LOG_REGEX in
<pre>as follows<pre>\${BUILD_LOG_REGEX,....}</pre>. You may also want to tinker with that. However, using the two attributes from solution 2 I can produce a well-formatted email that matches your requirement.Example Implementation of Solution 2
Since solution #2 is a superset of solution #1 I am not providing sample code for solution #1. Here is your code fitted with these recommended changes.
Here is the large pipeline I wrote to simulate your “environment”. Notably, I could not replicate your problem except by setting
addNewline=“false”so here I am explicitly setting it to true. Additionally I broke some of your tokens because they don't exist in my system.Resulting email
The resulting email looks like the following for me:
The reason you see line duplication is due my test script ( it's grabbing the echo command and the stdout ). Yours won't do that assuming the string is produced by the output of a command that does not contain the string itself.