Powershell script as executable giving "wrong" return code -1 in Bamboo

I have some simple PowerShell scripts that I injected into Bamboo executables by adding a path, such as C:\build-scripts\bamboo-build-scripts\clear-directory.ps1 , as the path for the executable for the new capacity in bamboo.

However, several scripts, even those that run correctly during the build process when they are made as a "script", will not work when they are run this way, providing a return code of -1. Here is an example from the build log:

 simple 18-Jun-2015 13:14:06 Failing task since return code of [C:\build-scripts\bamboo-build-scripts\update-checker.ps1 GeometryClassLibrary] was -1 while expected 0 

This happens with several PowerShell scripts and causes the rest of the procecss assembly to crash.

Here is an example PowerShell script that I execute by passing an argument to a directory:

 Remove-Item $args[0] -Force -Recurse [io.directory]::CreateDirectory($args[0]) 

Is there something I need to add to the PowerShell script in order to get it to exit with the correct code? Or am I not defining the executable correctly in Bamboo?

+6
source share
1 answer

You can try a few things:

Execution policy

Perhaps the scripts are not executed at all, perhaps because the policy is not executed. Try calling powershell.exe directly:

 powershell.exe -ExecutionPolicy Bypass -File C:\build-scripts\bamboo-build-scripts\clear-directory.ps1 

( see this answer for additional parameters )

Piping

NSClient ++ had problems with calls written in powershell due to problems with exit code. Their solution looked like this:

 cmd /c echo C:\build-scripts\bamboo-build-scripts\clear-directory.ps1; exit $LastExitCode | powershell.exe -Command - 

Perhaps this will give a more accurate code.

0
source

Source: https://habr.com/ru/post/989358/


All Articles