Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Access Bamboo variables in bash script

I want to access the global variables set in bamboo in a bash script that I am running on my local. How can I access those variable?

3 answers

The following works for me in a "script" task:

bash /path/to/some/shell/script/on/bamboo/server/

where /path/to/some/shell/script/on/bamboo/server/ looks something like:

# Note underscore in definition
echo "worldName was set to: ${bamboo_worldName}"
exit 0

And in the "Variables" tab of a plan, I set worldName to "foo".  When bamboo runs, it outputs:

worldName was set to: foo

Note that in the script task itself, it correctly reads and interprets a bamboo.variable, but when you run in a sub-shell (say, calling/running an external shell script from the "script" task), you just have to translate it to bamboo_variable.

Also, sorry for the very late reponse.

EDIT:  I only now read your last comment, which was basically, "can you modify the global variables set in Bamboo by running a script locally inside Bamboo?"  The answer is probably "no" - a cursory scan through the REST API showed that you can change them on a per-instance case (if they're a queued plan), or trigger a build/deploy via the REST API overriding existing variables, however, I didn't see a way to actually set the "Global Variables" in Bamboo overall directly.  Note that with some things, I've had to scrape HTML to figure out what's going on.  Essentially, create a Selenium "test" that automatically clicks through various buttons and whatnot to post the relevant information.  It's a terrible hack and highly fragile, and likely to break something if you're not careful.

In inline script you may have used bamboo.variable similarly use bamboo_variable. 

Like 박래철 likes this

True - I think the difference is that using `bamboo.variable` means that the Bamboo Java Process does a bulk string find/replace _before_ it creates the shell script that then gets executed.  We've shied away from using that, as we've mostly stopped doing "things" in the "Script" task - instead adding them to a shell script in the code repo, and executing from there.

In that case, `bamboo.variable` is not a valid env variable in shell or bash, so those fail.

Like 박래철 likes this
1 vote
Marcin Oles
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 01, 2015 • edited Nov 22, 2019

Hi Hardik,

to do so use this syntax:


for example

echo "Hello, ${bamboo.worldName}!"
exit ${bamboo.exitCode}

Such variables will not get evaluated by shell, because prior to being executed Bamboo will replace all identified variables with their values.

More detailed guide can be found here:

---------- UPDATE ----------

As I mentioned in the comment, substituting variables will not work for script tasks run from a file. Only inline scripts will be substituted.

A workaround for this would be to use variables during configuring the Script task, as script arguments or environment variables. See the screenshot for more info:



Hello Marcin, I have created a global variable for demo purpose. The variable is called demovariable I created a bash script as follows: #!/bin/bash echo ${bamboo.demovariable} I am getting the error '${bamboo.demovariable}: bad substitution' Am I doing anything wrong? P.S. Just to divert your attention to this important fact, I am trying to access these variables in a bash script running on my local machine and not as Bamboo inline script

Marcin Oles
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 04, 2015

"bad substitution" is an error message from bash. The variables are not being substituted, so they are left in the script which then fails to execute (bash and sh can't handle the dot in variable names). I've verified that variables will not be substituted in script files, only for inline scripts. That's probably the reason. As a workaround, you can use variables in "script arguments" and "environment variables" in the task configuration, and then use the arguments or env vars in the script. Cheers, Marcin

Hello Marcin, I did get the point wherein you mentioned why cannot the bash access the variable using the dot. But I am unable to understand the workaround that you have mentioned. Can you please explain that in greater detail?

Marcin Oles
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 05, 2015

Updated my answer with more details and a screenshot of an example.

Hello Marcin, Thanks for the prompt reply. I think we both are probably proceeding on different tasks I shall explain the exact requirement: I have bamboo configured on my machine. I have set some predefined global variables in Bamboo. I have a bash script running on my local machine performing some operations. Some results are being generated. I want to now updates these results into the global variables that are present in my bamboo automatically from my local bash script itself. Can you tell me how should I be doing that? Regards, Hardik

I have the same issue.


Specifically, I have a Variable:

* Variable name: JAVA_11_PATH

* Value: /usr/lib/jvm/java-11-amazon-corretto


And a script that I want to use like this:


./gradlew clean build



But that returns this error:


Value 'JAVA_11_PATH' given for Gradle property is invalid (Java home supplied is invalid)



If I manually substitute `JAVA_11_PATH` for the value in the script, it works. So obviously it's just the variable substitution that fails.


So, how can I make this work?

If you're using the "Script" task in Bamboo, you have two options:

  1. ${bamboo.JAVA_11_PATH}
  2. ${bamboo_JAVA_11_PATH}

I strongly recommend going with option 2.  Generally, I've found the "Script" task to be not so hot, other than to prototype.  We instead tend to copy/paste the contents of the "Script" task into an actual script in the codebase instead (for example a `` script in the codebase in, like `bin/`).  And then the "script" task just looks something like:


if [ ! -r ${BUILD_SCRIPT} ] ; then
  echo "ERROR: could not find ${BUILD_SCRIPT}" >&2

if ! ${BUILD_SCRIPT} ; then
  echo "ERROR:  executing ${BUILD_SCRIPT} failed" >&2
  # <do whatever relevant cleanup you need to do>

Managing that script in your code repo also means that it's far simpler to manage the actual build than to try to handle changes that happen in the Script task in Bamboo directly.  Note that the "config as code" has made it somewhat easier to manage, but even that is still pretty clunky.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events