Here's one environment variable MODEL in my Jenkins declarative script. But I am not able to use this MODEL variable into the email body. Though it is working fine in the email subject!
pipeline {
agent any
stages {
stage(‘Test’) {
environment {
MODEL = “Some ML Model v1.2.3”
}
steps {
...
}
post {
always {
emailext attachLog: true,
attachmentsPattern: ‘**/reports/*.html’,
mimeType: “text/html”,
to: '[email protected]’,
subject: “Test - ${env.MODEL} Build [${env.BUILD_NUMBER}]“,
body: '''<html>
<p><b>Regression Test Report</b></p>
<p>$MODEL</p>
<p>${MODEL}</p>
<p>"${MODEL}"</p>
<p>"${env.MODEL}"</p>
<p>""'${MODEL}'""</p>
<p>""'${env.MODEL}'""</p>
<p>"""${env.MODEL}"""</p>
<p>${ENV,var="MODEL"}</p>
<p>"${ENV,var="MODEL"}"</p>
<p>Build URL: $BUILD_URL</p>
<p>Build Status: $BUILD_STATUS</p>
<br />
<p><b>Console Output</b></p>
<pre>${BUILD_LOG_REGEX, regex="^.*test session starts.*$", showTruncatedLines=false}</pre>
<pre>${BUILD_LOG_EXCERPT, start="^.*test.*==$", end="^.*in.*==$"}</pre>
...
</html>'''
}
}
}
}
}
I have tried multiple things as shown, but this script is just producing following email body:
Also went through several links like the following but still did not get the drill. Please suggest something.
For such cases you need to use triple double quotes when defining template: