Reputation: 3399
In my jenkinsfile
I defined an environment variable:
env.PACKAGES = htmlPackageList
I tried accessing it from the template with ${PACKAGES}
and ${env.PACKAGES}
, but both times I just receive the email with a plain string.
template.html:
<pre style='line-height: 10px; color: green; font-size: 20px; white-space: pre; margin: 1em 0; display: block;'>$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS.<br/> </pre>
<br/>
Check console <a href="$BUILD_URL">Build URL</a> to view full results.<br/>
<br/>
<h4>Change list:</h4>
<div style="padding-left: 30px; padding-bottom: 15px;">
${CHANGES, showPaths=true, format="<div><b>%a</b>: %r %p </div><div style=\"padding-left:30px;\"> — “<em>%m</em>”</div>", pathFormat="</div><div style=\"padding-left:30px;\">%p"}
</div>
--<br/>
<h4>Published Packages:</h4>
${PACKAGES}
The email is invoked by:
success {
script{
emailext body: ('${FILE,path="Jenkins/Templates/template.html"}'),
to: "${env.EmailTo}",
subject: '[Jenkins] [$PROJECT_NAME] - [Build # $BUILD_NUMBER] - [$BUILD_STATUS]',
mimeType: 'text/html'
}
}
Upvotes: 1
Views: 1388
Reputation: 11
The below declaration in template(groovy) can fetch all the env variables from pipeline
<% def envEnviron = it.getAction("org.jenkinsci.plugins.workflow.cps.EnvActionImpl").getEnvironment()
println(envEnviron)
%\>
The below also can be used to get only the overridden variables in pipeline
<% def envOveriddenEnviron = it.getAction("org.jenkinsci.plugins.workflow.cps.EnvActionImpl").getOverriddenEnvironment()
println(envOveriddenEnviron)
%\>
Upvotes: 1