How to read Bamboo variables during code execution
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.
We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!
Summary
It's not possible to read Bamboo global variables when executing code, as this would pose a security risk and expose internal information. This article covers workarounds to pass Bamboo variables to the builders.
Environment
All Bamboo versions, with Maven, Ant, or other builders.
Solution
Passing variables as parameters
Although Bamboo variables are not directly available in the builder execution context (Maven, Ant, etc.), they can be passed as parameters to the builder. Please refer to Passing Bamboo variables to a build script for steps.
Environment variables
If you're using Maven or Ant as the build tool, it's possible to add environment variables to those apps, externally, and read them in the Java code. See Accessing Maven properties in Java and Ant: Using Environment Variables.
Script task
You can add a Script task that does and echo
of the value of the Bamboo Global variable to a file, and then have your Java code read it from that file.
Since Bamboo Global Variables are available within Bamboo's tasks, the Script task would have access to the value and could be used to output it to the system, which could then be used by the Java code.
Shell variables
If your goal is to use the variable to name files build by the builder tools, you can also set a variable in a shell
script, and use it to rename the files manually.