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.
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
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
}
else
{
Write-Host $Scope "OK."
Write-Host $lastExitCode
}
}
Code 2 - Error direct
Write-Host "DIRECT ERROR"
exit 2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.