I have a Jenkins Pipeline which sends email to the recipients using Jenkins email-ext plugin. In the emailext body, I have added HTML code to send the mail in a specific format. However, when I try to use the environment variable, it does not return the value of the variable.
In my pipeline, I have set
SERVICE_NAME = "Service Variable"
emailext body:
''' <html>
<body>
<div style="padding-left: 30px; padding-bottom: 15px;" color="blue">
<font color="navy" size="5"> <b> ${SERVICE_NAME} </b> </font> <br>
<b> Build </b> : <font color="blue"># ${BUILD_NUMBER} </font><br>
<b> Git Branch </b> : <font color="gray"> ${BRANCH_NAME} </font> <br>
<b> Status </b> : <font color="red"> ${BUILD_STATUS} </font><br>
<b> Cause </b> : <font color="gray"> ${BUILD_CAUSE} </font>
</div>
<div style="padding-left: 30px; padding-bottom: 15px;">
${CHANGES, showPaths=true, format="<div><b>Author</b> : <b> %a </b><br><b>Commit-Id</b> : %r <br> </div><div style=\\"padding-left:30px;\\"> <b> Message </b> : “<em>%m</em>”</div>", pathFormat="</div><div style=\\"padding-left:30px;\\">%p"}
</div>
</body>
</html>''' ,
mimeType: 'text/html',
subject: "Some subject ",
to: 'mail.com'
OUTPUT:- ${SERVICE_NAME}
Instead it should return "Service Variable" in the mail.
Any help regarding this please? Thanks!
Your issue is about string interpolation.
As said in Groovy Syntax:
As you provide triple-single-quoted string, you are specifically asking Groovy not to interpolate any variables in it.
To fix your issue and make string interpolation work, change triple-single-quoted into a triple-double-quoted string: