Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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.

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

190 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you