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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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
4,560,637
Community Members
 
Community Events
185
Community Groups

How do you add bamboo variable in powershell?

Hello All,

I'm having hard times to figure this out, I have the following powershell script , simple one:

$BambooPath = 'C:\StartFolder'
$RemoteWebPath = 'C:\DestFolder'
Copy-Item -Path $BambooPath -Destination $RemoteWebPath -Recurse

I wan't to replace in $BambooPath the C:\StartFolder with the bamboo.working.directory variable...anyone has an ideea how to do that?

4 answers

How to use Bamboo Variables in an EXTERNAL file powershell script.

This works when your powershell script is file based. You are calling your script using a Script Task.

Interpreter = Windows Powershell
Script location = File
Script file = [full path and filename of your powershell script]

From within your file based powershell script:

# notice the use of quotes here if you want to use the .replace extension method.
$mybranch = "$Env:bamboo_planRepository_branch".replace("/","-")

$buildNumber = $Env:bamboo_buildNumber

$myCustomVariable1 = $Env:bamboo_myCustomVariable1

The main difference between INLINE and EXTERNAL file base powershell scripts is the way you access the variable. In this example, simply prefix the bamboo variable with $Env: and replace the dots with underscores.

I hope this simple clarification with examples will help others stumbling over this question in the future.

How to use Bamboo Variables in an INLINE powershell script.

Critically, this ONLY works if your powershell script is INLINE. If your powershell script is in a file somewhere, then this will not work

Examples for inline use of bamboo variables in a powershell script:

$mybranch = "${bamboo.planRepository.branch}".replace("/","-")

$buildNumber = "${bamboo.buildNumber}"

$myCustomVariable1 = "${bamboo.myCustomVariable1}"

Whats going on:

$mybranch is a local variable, and is assigning the value of bamboo.planRepository.branch variable. In this example, we are replacing the 'forward slashes' with dashes. I thought that might help demonstrate use of the variables too.

One solution we found rather easy is to use the variables as arguments.

In your case you should use 

$BambooPath = $args[0]; 

And enter as argument : ${bamboo.build.working.directory}

This is not very helpful.  Maybe you can provide more detailed explanation how you can set it. I am trying to set some build variable from PS script

Hi Jacek,

 

We use a script that needs to know in which state it's used (build or deploy) and another parameter. In the Argument we have:

build ${bamboo.repository.git.branch}

Note that the parameters are split with a space.

 

For getting the parameters in your Powershell code use this.

$state= $args[0]; //returns "build"
$branch = $args[1]; //returns something like "master" or "feature/feature-name"

//Followed by your own code
0 votes
Timothy
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.
Nov 08, 2016
For task configuration fields, use the syntax ${bamboo.myvariablename}. For inline scripts, variables are exposed as shell environment variables which can be accessed using the syntax $bamboo_MY_VARIABLE_NAME (Linux/Mac OS X) or %BAMBOO_MY_VARIABLE_NAME% (Windows).

If it were that easy...It's not working. sad

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events