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

Is it possible to set Bamboo variables in one stage ( via custom task) and retrieve it in a different stage

Kepio Feb 14, 2012

Use case
A task may define some *custom build variable* that would need to later be retrieved in subsequent tasks.
The current mechanism to handle this is to share artifacts between the tasks - the problem with this approach is that the "native" bamboo tasks, such as the ant task could not access this "custom build variables"; we would need to write a wrapper script that parses the artifact then invoked the ant command. Furthermore, using artifacts requires to add extra logic in every task to read/write to the artifact.

Is it possible to set a bamboo build variable ( attach it to the plan, see code below) and access it in later stages - without going through artifacts?

Tested case
I created custom build variables using the variableDefinitionManager

VariableDefinition vd = new VariableDefinitionImpl();
variableDefinitions.add( vd );

What currently works:

* Pass variables between tasks

Stage 1
task 1A: set_plan_variable myVar
task 1B : print_variable myVar

What does not work:
* Pass variables between a jobs (expected not to work since jobs can be concurrent)

* Pass variables between a stages

Stage 1
task 1A: set_plan_variable myVar
Stage 2:
task 2A : print_variable myVar


I opened to request the feature, but if someone has a magic trick to share, please do !

1 answer

1 accepted

3 votes
Answer accepted
Przemek Bruski Atlassian Team Feb 14, 2012

I think the only way is to have a finalising task that puts all variables into a file defined as an artifact and a task that fetches them from that file in another stage/Job.

As you've mentioned, by design, you won't be able to do that between Jobs in the same Stage. That's why we've introduced Stages in the first place - to serialise Jobs and allow them to pass information between one another.

Kepio Feb 17, 2012

Thanks Przemek - that makes perfect sense - I wrote a task that dump the custom build environment variables into a java property file and another task to load it at a later stage ( the property file is defined as artifact) - the problem I have is that the variables get loaded as environment variables and not as a bamboo build variables - as such, they can't be used as arguments into tasks - for instance, to configure the working sub-directory, I can't use $my_subdir. If however, I run a simple bash task that "echo $my_subdir" it will echo it properly.

I'm using the below routine to load the variables into the environment :

List<VariableDefinition> variableDefinitions = new ArrayList<VariableDefinition>();
VariableDefinition vd = new VariableDefinitionImpl(key,value,thisPlan,VariableType.PLAN);
variableDefinitions.add( vd );

Is there a better way to load a pair of "key/value" into a build variable from a task and access it later via $(key) or $(bamboo.key}

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

8,123 views 24 36
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