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 votes
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
Community showcase
Asked Thursday in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

1,509 views 7 7
View question

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