If you are using the email-ext Jenkins plugin to send out emails,there is a "build" object that contains a lot of information about your Jenkins job.
I would do the following:
-
Print out the properties inside this object by adding the following code to your template:
<% println build.properties.collect{it}.join('<br />') %> -
View the email template output. You can either use the Jenkins "Email Template Testing" feature or just run your job. You should see a whole bunch of "KEY=VALUE" print outs.
-
Look for the environment variable you are interested in. If your environment variable is listed in?
environment={BUILD_NUMBER=45,BUILD_DISPLAY_NAME=#45...},you can just call?build.environment['BUILD_NUMBER']?to get 45. -
If you want to inject custom environment variables I would suggest installing the?Env Inject Plugin,defining your variables through that plugin and then looking for the variable in build.envVars
<% println build.environment['BUILD_NUMBER'] %>
<%=build.environment['BUILD_NUMBER']%>
