尽管非零Python退出代码,但GitHub Action并没有显示错误
我有一个Python脚本,该脚本在GitHub操作中以错误代码退出,但动作仍然显示出成功。我想在抛出非零退出代码时显示错误。脚本或工作流程中应该更改任何内容吗?
Python脚本:
import sys
import os
error_code = 256
print(f'error_code: {error_code}')
os._exit(error_code)
# have also tried sys.exit(error_code)
GitHub工作流程:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: test
run: python3 ./test_error_exit.py
I have a python script that exits with an error code inside a Github action, but the action still shows a success. I'd like for it to show an error when a non-zero exit code is thrown. Is there anything that should be changed in the script or workflow?
Python script:
import sys
import os
error_code = 256
print(f'error_code: {error_code}')
os._exit(error_code)
# have also tried sys.exit(error_code)
Github Workflow:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: test
run: python3 ./test_error_exit.py
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在基于Linux的系统上,过程退出代码是返回的数字的8个最不重要的位。
这意味着返回0-255是有效的,此后它可以绕开。 (256变为0,257成为1等)
请用像5这样的出口代码重试。
On linux based systems, process exit codes are the 8 least significant bits of the number returned.
This means returning 0-255 is valid, and after that it wraps around. (256 becoming 0, 257 becoming 1, etc.)
Please try again with an exit code like 5.