Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to check if a Variable is set?


So I have 2 variables in my script, one that is set when the user triggers the deployment manually and second when the deployment is triggered automatically. Therefore, one of the variables will not be set.

I've tried:

if [[ -z "${bamboo.ManualBuildTriggerReason.userName}" ]]; then

but I get a bad substitution error. In the case because the bamboo.ManualBuildTriggerReason.userName doesn't exists when the job deploys automatically.


Then I've tried something like


Still got the same error.

What is the best way to check if the variable is set or not?


LE: It's related to

4 answers

I made a workaround here to check:


PARAMETER_NO_TRAIL_SPACE="$(echo -e "${bamboo.ManualBuildTriggerReason.userName}| sed -e 's/[[:space:]]*$//')"

if [[ -z "$PARAMETER_NO_TRAIL_SPACE" ]]; then    

An indicator of a referenced variable not being set is if your build fails:

You can:

  • reference a global or context specific variable in a build plan or deployment project
  • reference a variable which references another one, deep recursion is allowed

There are couple of limitations:

  • referencing a variable which isn't defined is an error, whole build or deployment will fail if you reference such variable
  • cycles are not allowed and are considered as build or deployment project error.

 If you want to check if a variable is set to the value you'd expect, I'd just create a script task that printed a message with the variable and look for it in the logs while debugging.

echo "Hello ${bamboo.ManualBuildTriggerReason.userName}!"


This doesn't help me, let's say I have some variables in my and they are loaded into bamboo and they are stage specific. 

I would want to check if the variable is defined like a simple bash command: 

if [[ -v blabla ]]; 

this checks that $blabla variable exists.

Is that so complex to do in Bamboo?  

Only ASCII letters and digits and "_" are supported well on all linux systems and shell scripts as variable names. (regexp:   [a-zA-Z_][a-zA-Z_0-9]* )

See the posix definition of a name for example:

So the workaround is to assign the value to a variable name without dots by using a tool that supports the dots in the variable name like:

bamboo_ManualBuildTriggerReason_userName=$(env | grep ^bamboo\\.ManualBuildTriggerReason\\.userName= | cut -d= -f2-)


I am having this same problem.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bamboo

Bamboo Data Center on Kubernetes

Hi, If you are running self-managed environments and looking to adopt modern infrastructure, Bamboo Data Center can now be deployed in a Kubernetes cluster. By leveraging Kubernetes, you can easily...

46 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you