In Bamboo how can you access\edit plan and global variables in windows powershell script

I'd like to be able to read and update plan and global variables from PowerShell scripts. Ive seen that you should be able to take a variable like

bamboo.buildNumber

and access it in script by using

$bamboo_buildNumber

and i've also seen that you need to do

$BAMBOO_BUILDNUMBER

but neither is working for me.

What's the correct way to access these varialbes? And can you set them and then have that value available to other tasks, stages, deployment projects, ect...

1 answer

If you run it as a Script command or pass in as arguments you can use Bamboo Variables in PowerShell. No matter where you use bamboo variables the format is the same

${bamboo.buildNumber}

If you continue to have problems, make sure to check the log as it shows which variables it's substituting before calling anything:

command	29-Jan-2014 09:24:36	Substituting variable: ${bamboo.buildKey} with TOOLS-TINK-BUILD
command	29-Jan-2014 09:24:36	Substituting variable: ${bamboo.buildNumber} with 2
command	29-Jan-2014 09:24:36	Substituting variable: ${bamboo.buildTimeStamp} with 2014-01-29T09:24:21.118-05:00
command	29-Jan-2014 09:24:36	Substituting variable: ${bamboo.repository.revision.number} with 187290
command	29-Jan-2014 09:24:36	Substituting variable: ${bamboo.repository.branch.name} with Trunk
As for editing, there is a plugin that can inject variables from a text file which you could create with PowerShell; personally, I've got inconsistent results with it so I abandoned it but here it is: https://marketplace.atlassian.com/plugins/com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin. I'm not sure if the API will allow changes to any Global Variables or if it does whether the changes would be available in the same build in a later step (might cache).


Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

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...

1,068 views 0 5
Read article

Atlassian User Groups

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!

Find my local user group

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

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot