How to show executed build plan variable values in notification email template?
Asked by Bart Szpak:

The use case is simple:

- At the end of a build plan run (ie. Build Release), there is a versions.txt file that gets generated and I want to have the contents of that file presented in the "All Completed Builds" notification email subject line.

I can thus far:

- Extract the contents of that file and inject them as bamboo variables using the "Inject Bamboo variables" Task or simply print them to screen/logs.

- Modify the notification template files (.ftl)

Where I'm stuck is identifying the bamboo objects referencing these 'injected variables'. Even some of the built-in bamboo variables ie. ( ${bamboo.build.working.directory} ) don't work as objects in the Freemarker markup templates.

There must be an easy way to show desired build version info of a given build plan in the notification email subject line (and no, ${bamboo.buildNumber} is not it).

Any help would be appreciated.


Answers:
author: Steffen Opel _Utoolity_
body: Based on [Modifying notification templates](https://confluence.atlassian.com/bamboo/modifying-notification-templates-289276982.html), I think you'll need to explore the Java interfaces that are backing the Freemarker ${buildSummary} and ${deploymentResult} variables, i.e. the Java [BuildResultsSummary](https://docs.atlassian.com/atlassian-bamboo/latest/com/atlassian/bamboo/resultsummary/BuildResultsSummary.html) and [DeploymentResult](https://docs.atlassian.com/atlassian-bamboo/latest/com/atlassian/bamboo/deployments/results/DeploymentResult.html) interfaces respectively.

The former provides an Iterable [getResultVariables()](https://docs.atlassian.com/atlassian-bamboo/6.2.3/com/atlassian/bamboo/resultsummary/BuildResultsSummary.html#getResultVariables--) in turn, which might be what you are looking for - Carolyn van Slyck's [Bamboo Deployment Notifications](https://bitbucket.org/carolynvs/bamboo-deployment-notifications) provides examples how to conceptually access those interfaces from Freemarker (albeit only for ${deploymentResult}), e.g. in template [EmailSubject.ftl](https://bitbucket.org/carolynvs/bamboo-deployment-notifications/src/b6283c638d65a6a3d82a8dffc2d0ffda0597f098/src/main/resources/templates/MultipleFailedDeployments/EmailSubject.ftl?at=master&fileviewer=file-view-default):

```
[#-- @ftlvariable name="deploymentResult" type="com.atlassian.bamboo.deployments.results.DeploymentResult" --]
[#-- @ftlvariable name="deploymentProject" type="com.atlassian.bamboo.deployments.projects.DeploymentProject" --]
[#-- @ftlvariable name="numFailures" type="Integer" --]
[#assign deployment=deploymentProject.name /]
[#assign release=deploymentResult.deploymentVersion.name /]
[#assign environment=deploymentResult.environment.name /]
${deployment} ${release}[#t]
[#if deploymentResult.deploymentState == "Successful"] was successfully deployed to ${environment} after ${numFailures} [#if numFailures = 1]failure[#else]failures[/#if].[#rt]
[#elseif deploymentResult.deploymentState == "Failed"] failed deploying to ${environment} (${numFailures} [#if numFailures = 1]times[#else]times[/#if]).[#rt]
[#else] stopped deploying to ${environment}[#rt]
[/#if]
```

For a Bamboo version x.y.z installation, you can inspect the built in Freemarker deployment notification templates within the following artifact (search for *\*.ftl*):

*\<bamboo-install\>/atlassian-bamboo/WEB-INF/lib/atlassian-bamboo-deployments-x.y.z.jar*

comments: author: Bart Szpak
body: Thank you for the info, Steffan, and apologies on the delayed reply.

Had to move onto another task that could at least get completed.

The 'getResultVariables()' method certainly does sound like what I'm looking for, I'm still a little unclear as how these methods actually get called in the Freemarker template files (.ftl) and what variables are available as it seems not all ${bamboo.\*} build variables are accessible through either BuildResultsSummary or Build classes/macros.

In any case, I will revisit this area after the holidays when I can look at it from a refreshed perspective.

Thanks again!


author: Abhishek S
body: [@Steffen Opel _Utoolity_](/t5/user/viewprofilepage/user-id/781567)
> I'm still a little unclear as how these methods actually get called in the Freemarker template files (.ftl) and what variables are available

I am still unclear about this? Can you please help me out?

My use case is: <https://community.atlassian.com/t5/Bamboo-questions/How-to-put-checkout-revision-number-of-a-build-in-ftl-email/qaq-p/2273559>