allow_failure:exit_codes unusable with windows shell executor because exit code is always 1
Summary
With the shell executor on windows, a job with a failing script line always exits with code 1 instead of the failing exit code. This bug does not occur if using the docker-windows executor.
This renders allow_failure exit_codes unusable if using the shell executor, because it is impossible to distinguish between types of failures.
Steps to reproduce
- setup gitlab runner with shell executor (repros on revision=b37d3da9 version=14.3.0)
- use the following .gitlab-ci.yml:
broken_job:
script:
- python -c "import sys;sys.exit(100)"
# Or use: powershell { exit 100 }
# Or use: exit 100
allow_failure:
exit_codes: 100
- run the pipeline and see the job fail
Example Project
https://gitlab.com/ken.kania/exit-code-bug
Job should be allowed to fail, but instead fails: https://gitlab.com/ken.kania/exit-code-bug/-/pipelines/376260769
What is the current bug behavior?
An item in a job's script array that results in any nonzero exit code causes the job to exit with code 1.
What is the expected correct behavior?
An item in a job's script array that results in any nonzero exit code causes the job to exit with the corresponding exit code.
Relevant logs and/or screenshots
DEBUG: 219+ >>>> echo "`$ python -c `"import sys;sys.exit(100)`""
$ python -c "import sys;sys.exit(100)"
DEBUG: 220+ >>>> python -c "import sys;sys.exit(100)"
DEBUG: 221+ if( >>>> !$?) { Exit &{if($LASTEXITCODE) {$LASTEXITCODE} else {1}}
}
DEBUG: 221+ if(!$?) { >>>> Exit &{if($LASTEXITCODE) {$LASTEXITCODE} else {1}}
}
DEBUG: 221+ if(!$?) { Exit >>>> &{if($LASTEXITCODE) {$LASTEXITCODE} else {1}}
}
DEBUG: 221+ if(!$?) { Exit & >>>> {if($LASTEXITCODE) {$LASTEXITCODE} else {1}}
}
DEBUG: ! CALL function '<ScriptBlock>' (defined in file
'C:\Windows\TEMP\build_script924156239\script.ps1')
DEBUG: 221+ if(!$?) { Exit &{if( >>>> $LASTEXITCODE) {$LASTEXITCODE} else {1}}
}
DEBUG: 221+ if(!$?) { Exit &{if($LASTEXITCODE) { >>>> $LASTEXITCODE} else {1}}
}
DEBUG: 221+ if(!$?) { Exit &{if($LASTEXITCODE) {$LASTEXITCODE} else {1} >>>> }
}
...
ERROR: Job failed: exit status 1
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Possible fixes
Edited by Ken Kania