Check if variable exists

Is it possible for a bamboo-build to check if a variable exists? I'm having some trouble building a nightly-build-plan which can be run manually, because if it's run manually it passes the ${bamboo.ManualBuildTriggerReason.userName} to my shell-script which executes the nightly build, but if it's run scheduled it exits with an error "bad substitution" because the variable doesn't exist. I'd imagine my problem would be solved if I somehow could check beforehand, if the variable exists and only use it, if it does.

2 answers

Perhaps a little bit tool late. There is a workaround.

In your bamboo plan, create a variable with the name: ManualBuildTriggerReason.userName

And leave its value empty.

In your script, this variable will be empty in case of a triggered build.

It will not be empty in case of a manual build.

0 vote
Timothy Chin Community Champion May 04, 2014

What happens if you do an if-else in your shell script?

The job wont run, because it exits as soon as I mention the ${bamboo.ManualBuildTriggerReason.userName}-Variable, since it's nonexistant when the job is run automatically.
Timothy Chin Community Champion May 06, 2014

Mind sharing the script?

I don't think, that the script has anything to do with what I'm asking, but here it is:

#!/bin/bash

user=$1;
pw=$2;
build_plans=(A-A A-B A-C A-D A-E A-F);
for plan in ${build_plans[@]}; do
        `dirname $0`/bamboo.sh --user $user --password $pw --action queueBuild --build "$plan" --wait
done
exit 0

Where bamboo.sh holds the server-info.

I'm also looking for an answer to this question, i've tried all sorts of ways to test if the bamboo variables exist, but if they do not exist bamboo intercepts things before the script is even run which is very annoying.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,452 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you