Powershell runner ignores `-ErrorAction Ignore` parameter and thus script fails
Summary
In PowerShell scripts performed by CI in before_script section, the commands with -ErrorAction Ignore and -ErrorAction SilentlyContinue may fail despite the -ErrorAction value.
Piece of log:
$ Remove-Item $Env:CLONE_DIR -Recurse -ErrorAction Ignore
DEBUG: 194+ >>>> Remove-Item DirectoryThatDoesNotExist -Recurse -ErrorAction Ignore
DEBUG: 195+ if( >>>> !$?) { Exit $LASTEXITCODE }
DEBUG: 195+ if(!$?) { >>>> Exit $LASTEXITCODE }
From PowerShell point of view, it's not a bug, because $? returns False regardless of ErrorAction value.
However, while my PS script doesn't fail when I run in on my PC, on CI job it does.
Steps to reproduce
- Register a Windows CI runner with
shellexecutor (powershell). - In
before_scriptsection of your build script, write the following:Remove-Item DirectoryThatDoesNotExist -Recurse -ErrorAction Ignore echo "Build didn't fail" - Observe the build failing on
Remove-Itemcommand.
What is the current bug behavior?
Executor checks the command result by checking $? value. This value doesn't take into account ErrorAction parameter
What is the expected correct behavior?
Executor checks the command result in a different way that takes into account ErrorAction parameter.
Environment
GitLab Enterprise Edition 12.0.0-ee
Windows Server 2016 (14393)
P.S.
Didn't try it anywhere outside of before_script.