Repository navigation
Description
Describe the bug
Powershell does not return the correct exit code if it is non-zero and not 1.
To Reproduce
Steps to reproduce the behavior:
- Create an action that outputs an exit code that is not 0 or 1.
run: php -r "exit(42);"
shell: pwsh
- See error, as in this example from https://github.com/johnstevenson/runner-actions-test/actions/runs/48177580 which shows the correct behaviour for
cmdandbashand the error frompwsh.
Expected behavior
For powershell to return the exit code returned by the script.
Runner Version and Platform
Current runner version: 2.165.2
Tested on ubuntu-latest, macos-latest and windows-latest
See https://github.com/johnstevenson/runner-actions-test/actions/runs/48202446 for tests that use .bat, .sh and .ps1 scripts rather than using the php code.
What's not working?
The code that is appended to the powershell script in FixUpScriptContents:
| var append = @"if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }"; |
This can be fixed by either changing the line to:
var append = @"if (Test-Path -LiteralPath variable:\LASTEXITCODE) { $Host.SetShouldExit($LASTEXITCODE) }"; or by executing the script as a file, rather than a command which always returns the correct exit code:
runner/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs
Lines 12 to 13 in d80ab09
| ["pwsh"] = "-command \". '{0}'\"", | |
| ["powershell"] = "-command \". '{0}'\"", |
["pwsh"] = "-file \"'{0}'\""
["powershell"] = "-file \"'{0}'\"",
Incidentally, the documentation at https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell shows the powershell internal commands as pwsh -command "& '{0}'" rather than pwsh -command ". '{0}'", but I'm not sure where to report this.

Activity
bryanmacfarlane commentedon Mar 2, 2020
@thboop - this is a dupe right?
thboop commentedon Mar 3, 2020
I do not believe so.
cprosser-clear commentedon Oct 28, 2020
Is this being worked on? This is causing a lot of problems for us.
Output correct error codes actions#351
tomer-ds commentedon Nov 9, 2022
Hi all... any updates on this?
Tried the same test for LASTEXITCODE and same result of course
bartekpacia commentedon May 9, 2023
This problem makes it easy to miss test failures on Windows! IMHO it should be prioritized.
balupton commentedon Nov 15, 2025
This is reproducible simply with:
The exit status will still be
1, despite locally such results in the correct exit status.ci: wsl: add SetShouldExit
ci: refinements to WSL flow
Stop the Windows clean-machine check failing on its own probe exit code
CI: prove the installer works on a machine with no developer toolchain (
fix(ci): Verify exe 末尾显式 exit 0,摆脱残留的 LASTEXITCODE