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

Check if variable exists

V May 4, 2014

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

2 votes
Kristof Boeykens February 17, 2016

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2014

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

V May 4, 2014
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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 6, 2014

Mind sharing the script?

V May 7, 2014

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.

gwohletz December 15, 2015

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
TAGS
AUG Leaders

Atlassian Community Events