Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Why does Bamboo build system not respect PowerShell return codes?

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
    scripts:
      - <FAILING COMMAND>

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
    scripts:
      - <FAILING COMMAND>

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

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

Suggest an answer

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

Bamboo Data Center 8.1 is now available

G’day Bamboo customers, Bamboo DC 8.1 is now available with it the following features and programs: SAML 2.0, OpenID Connect, and Crowd SSO In order to help admins with a simplified user manage...

204 views 0 4
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