How do you access Bamboo build variables in a custom task plugin

Matt Curtis March 4, 2013

Hi all,

I'm writing a proof of concept Bamboo Task module having started from the basic HelloWorld example in the documentation. To begin I just want to log out some key build information.

We want to access Bamboo build/plan variables like bamboo.buildNumber, bamboo.custom.svn.revision.number as well as usernames and things but I'm struggling to find any examples of this in the documentation.

I looked at a few maps from the TaskContext object which were all empty including:

  • taskContext.getConfigurationMap()
  • taskContext.getBuildContext().getBuildDefinition().getCustomConfiguration()
  • taskContext.getBuildContext().getVariableContext().getDefinitions()

An example would be great to show how these should be accessed (and if one of the above should not be empty).

Thanks in advance!

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Rasike Abeyratne May 23, 2018
VariableContext variables = taskContext.getBuildContext().getVariableContext();
VariableDefinitionContext variable = variables.getEffectiveVariables().get("release_new_tag");
String newTag = variable.getValue();

Through above was able to access the bamboo custom variable "release_new_tag" - define for the specific plan

For access bamboo variables should use methods provided by sdk. e.g. taskContext.getBuildContext().getBuildNumber();
Tim Eddelbüttel
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.
March 18, 2019

Your snippet helps me to figure out how I can access my variables.

Thanks.

1 vote
Mibex_Software
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.
January 23, 2015

Hi,

You can inject an instance of CustomVariableContext into your task and then use the following to get the build variables:

Map<String, String> buildVariables = customVariableContext.getVariables(taskContext.getCommonContext());

 

Hope this helps.

Kind regards,

Michael

0 votes
James Dumay
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.
March 5, 2013

you can look these up via taskContext.getBuildContext().getCustomDataMap().get() but take off the bamboo. prefix before looking them up (eg instead of bamboo.buildNumber it is simply buildNumber)

Matt Curtis March 5, 2013

Hi James,

Thanks for the reply. That 'getCustomDataMap' method doesn't seem to exist on the BuildContext object though? I had a look and couldn't see anything similar (other than the 3 maps I listed above which didn't work).

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events