Cake.Powershell icon indicating copy to clipboard operation
Cake.Powershell copied to clipboard

No error is throw when exit code is not equal to `1`

Open kevbite opened this issue 6 years ago • 2 comments

Not sure if this is intentional or not but I expect that running the following script would throw an exception with a none 0 exit code?

TestScript.ps1

exit 1

build.cake

Task("Default")
    .Does(() => 
    {
        StartPowershellFile("TestScript.ps1");
    });

kevbite avatar Apr 18 '18 16:04 kevbite

I would be happy to change this but I'm wary that it makes assumptions about the scripts people are running. I'll leave this issue open and see if anyone chimes in on the conversation 👍

SharpeRAD avatar Apr 22 '18 09:04 SharpeRAD

Cool, at the moment I've worked around it with a Write-Error which then throws an exception.

Write-Error "Error Code Not Zero"
exit 1

A lot of deployment tools when running PowerShell scripts check the return code, It's why I had the assumption it should throw an exception back up and fail the build step.

I'm also happy to change the code and submit a pull request if you're happy to push in this feature?

kevbite avatar Apr 22 '18 15:04 kevbite