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?
I created custom build variables using the variableDefinitionManager
VariableDefinition vd = new VariableDefinitionImpl(); vd.setPlan(plan); vd.setVariableType(VariableType.PLAN); vd.setKey(k); vd.setValue(v); variableDefinitions.add( vd ); variableDefinitionManager.saveVariableDefinitions(variableDefinitions);
What currently works:
* Pass variables between tasks
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
task 1A: set_plan_variable myVar
task 2A : print_variable myVar
I opened https://jira.atlassian.com/browse/BAM-10899 to request the feature, but if someone has a magic trick to share, please do !
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 ); variableDefinitionManager.saveVariableDefinitions(variableDefinitions);
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}
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.Read more
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...
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!
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