Bamboo variable resolve to empty string in powershell script

I've got a powershell script within a git repository that I use to build the project.

In the script, I'm trying to run the following command

Get-ChildItem -Path ${bamboo.build.working.directory}\src -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

and the above returns the following error

11-Feb-2016 12:39:43Get-ChildItem : Access to the path 'C:\cygwin\home\Administrator\.ssh' is denied.
11-Feb-2016 12:39:43At C:\build\FCL-FCRP-JOB1\Build\01_Build.ps1:26 char:1
11-Feb-2016 12:39:43+ Get-ChildItem -Path ${bamboo.build.working.directory}\src -Filter project.json - ...

The above script would run fine as INLINE, but the variable would resolve to empty string if it ran as a File.

Does anyone experience the same problem? Or am I missing something here?

Thank you.

2 answers

1 accepted

Bamboo can indeed only expand variables when you use an inline script.
When you use a script file, PowerShell has absolutely no knowledge what those ${bamboo...} things are.

Passing them as arguments, or use the Bamboo environment variables, will do the trick.

To answer my own question, it turns out if you use powershell script inline, bamboo automatically substitute the bamboo variable into their respective values. However if you run it as a file, then you need to pass in the bamboo variable as arguments, so you need a param block inside the script file.

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,071 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