Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Ryan Vice January 28, 2014

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

1 vote
Jason Monsorno
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 28, 2014

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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events