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

Powershell with Bamboo

greg ricker October 3, 2011

I am trying to use PowerShell scripts as part of a custom build job. The PS script is started but never ends. I have read that PS can't be called directly from Bamboo. I did get this to work using a batch file to launch PowerShell but this seems a poor solution.

12 answers

1 accepted

6 votes
Answer accepted
Craig February 6, 2012

I set up Powershell as a command, and ran it with the following arguments

-command "echo do-your-commands" < NUL

The < NUL is the key part.

Daniel Turner March 2, 2012

Legend!!! Adding " < NUL" to the end fixed it for me. Thanks!!

Craig May 7, 2013

You can also run script files as follows:

-NonInteractive -ExecutionPolicy Unrestricted -File C:\Path-to\Script.ps1 "arg" arg

Craig September 3, 2013

I have found this solution is less reliable with Bamboo 5.1. Instead I've created a small bat file which is where my 'powershell' executable now points to. It contains:

REM http://serverfault.com/questions/437504/why-does-psexec-hang-after-successfully-running-a-powershell-script
SET ps=C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
C:\Windows\System32\cmd.exe /c "echo . | %ps% -NonInteractive -ExecutionPolicy Unrestricted -File D:\%1.ps1 %2 %3 %4 %5 %6"

Then I have a number of powershell scripts in the same folder including an all-purpose one called Exec.ps1 which contains:

param([string]$command)
#replacement for -command "some-power-shell-stuff" &lt; NUL
invoke-expression $command

0 votes
Sergey Podobry _Stellarity Software_
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.
June 6, 2013

Hi guys,

You are welcome to check out the PowerShell Task plugin for Bamboo! It handles all nasty stuff and lets you just create and run PowerShell scripts without a hassle.

0 votes
Marco_Wlotzka April 16, 2013

Hi,

Still have issues getting error codes returned to bamboo. I have created a batch file and configure it as a global command:

C:\Windows\System32\cmd.exe /c "echo aaa | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe %*; exit $LASTEXITCODE"

But still no exitcode in sight - any hints?


0 votes
Sagar Parikh January 7, 2013

you can just run:

E:\>powershell -command "& {YourPSCommand}"

E:\>powershell -command "& {get-childitem}"

0 votes
greg ricker October 5, 2011

I tried creating a batchfile (see below) where the argument is the PS script file. This works but task completes before the script does. The department seems heavily invested in Powershell but I'd be open to hearing other scripting solutions.

C:\Windows\System32\cmd.exe /c "echo aaa | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe %*"

0 votes
Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2011

How about:

start c:\path\to\powershell

?

Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2011

start /wait

?

Christopher Martin October 5, 2011

This did run the script, however the Bamboo task started and finished basically instantly, and there was no log output or anything.

Christopher Martin October 5, 2011

Same result: Instant task completion and no log of any kind, although the script did execute.

0 votes
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2011

Some suggestions on stackoverflow, although none of them seem especially convincing: http://stackoverflow.com/questions/2041799/powershell-script-gets-stuck-doesnt-exit-when-called-from-batch-file

0 votes
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2011

I've never tried integrating Powershell with Bamboo before, but have you tried adding an explicit "exit" command at the end of your PS script to force the console to close?

Christopher Martin October 4, 2011

Yes, I've tried exit 0 and exit -1, but in both cases the task kept running.

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2011

Blarg, that's disappointing :-(

0 votes
Christopher Martin October 4, 2011

I'm having the same issue. The powershell task doesn't exit, either using a command task, or a script task.

0 votes
greg ricker October 3, 2011

I created a task with PowerShell as the executable. My script is the argument. When the Plan is run I can see that PowerShell is launched against my script. But the Plan never exits.

0 votes
Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 3, 2011

Does it work if you use Script Task and set the Inline Script to:

c:\path\to\Powershell.exe YourScript

?

0 votes
Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 3, 2011

How are you currently starting PS?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events