Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

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

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.

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
Community showcase
Published in Bamboo

Bamboo - introducing LTS releases

We know that many of you have been asking for Long Term Support versions for Bamboo, as managing large, complex instances can require plenty of lead time and planning to prepare for an upgrade. To ...

349 views 0 8
Read article

Atlassian Community Events