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

Why does Bamboo build system not respect PowerShell return codes?

Aron Weiler December 7, 2021

I am using Bamboo Server 7.2.3.

Whenever I use WINDOWS_POWER_SHELL as the interpreter for scripts that I am running (either in the UI, or in YAML), I do not get a failed job / task when the script fails.

Example YAML (does not fail the build):

- script:
    interpreter: WINDOWS_POWER_SHELL

I would expect the above code to fail the job that is running this script task, but it does not.

The following code, however, DOES fail the build- notice that I am using the native script interpreter, BINSH_OR_CMDEXE.

Example YAML (fails correctly):

- script:
    interpreter: BINSH_OR_CMDEXE

This is pretty annoying, and I am wondering if I am crazy, or if there is a known bug in bamboo that would speak to this, or even hopefully a solution to this problem.

1 answer

1 vote
Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 7, 2021

Hey @Aron Weiler

Unfortunately, exit code handling in Powershell is not the most friendly. You'll need to exit with the exit code if it's non zero manually. For example, after each Invoke-Command you could set it up as follows:

Invoke-Command -ScriptBlock {command123 --options --setting 123}
if ($lastexitcode -ne 0) { exit $lastexitcode }

Invoke-Command -ScriptBlock {command123 --options --setting 456}
if ($lastexitcode -ne 0) { exit $lastexitcode }

Because the exit code will change after each command is invoked, you'll need it after each separate command where you could expect a failure that you'd want the build to abort.

Hope this helps. Let us know if you have any questions or concerns.


Eduardo Alvarenga
Atlassian Support APAC

I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 6, 2022

Hey @Eduardo Alvarenga ,


I have tried your solution, but it is not working. The follwing code ist executed in a "test.ps1" file from a YAML spec.


Code 1 - Error by function

function CheckErrorlevel($Scope){
if($lastExitCode -ne "0")
Write-Host "Error: " $Scope " (" $lastExitCode ")"
exit -100
Write-Host $Scope "OK."
Write-Host $lastExitCode


Code 2 - Error direct

exit 2


Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events