英文:
GitHub Actions completes job as success even it receives non-zero exit code
问题
我创建了 test.bat
以便从GitHub Actions执行。我遇到的问题是,即使从 test.bat
收到非零退出代码,GitHub Actions 也会将作业标记为成功。
以下是GitHub Actions的YAML文件。
jobs:
run_test:
runs-on: [self-hosted, Windows]
steps:
- run: ./test.bat
以下是执行测试的 test.bat
文件。
REM 运行测试,并在测试失败时返回非零退出代码。
test.exe -fail
REM 现在,假设测试失败,它返回退出代码 4。
echo %error_level%
现在,即使收到非零退出代码(为4),GitHub Actions也将作业标记为成功。
如果我删除 echo %error_level%
,那么GitHub Actions会正确将作业标记为失败。
为什么?
英文:
I made my test.bat
to be executed from GitHub Actions. The issue I have is that GitHub Actions completes job as success even it receives non-zero exit code from the test.bat
.
Here is the YAML file for GitHub Actions.
<!-- language: lang-yml -->
jobs:
run_test:
runs-on: [self-hosted,Windows]
steps:
- run: ./test.bat
Here is the test.bat
file that executes test.
<!-- language: lang-bat -->
REM This runs test and returns non-zero exit code when test fails.
test.exe -fail
REM Now, assume test failed, and it retruns exit code 4.
echo %error_level%
Now, GitHub Actions completes the job as success even it receves non-zero exit code (which is 4).
If I remove echo %error_level%
then GitHub Action completes the job as fail, properly.
Why?
答案1
得分: 1
The echo
command succeeds successfully and returns an exit code of 0.
Make sure you either capture the ERRORLEVEL
:
REM This runs the test and returns a non-zero exit code when the test fails.
test.exe -fail
set return_code=%ERRORLEVEL%
REM Now, assume the test failed, and it returns an exit code of 4.
echo %return_code%
exit %return_code%
Or do an if
statement and return your own exit code.
REM This runs the test and returns a non-zero exit code when the test fails.
test.exe -fail
IF NOT %ERRORLEVEL% == 0 (
echo %ERRORLEVEL%
exit 1
)
英文:
The echo
command succeeds sucessfully and returns an exit code of 0.
Make sure you either capture the ERRORLEVEL
:
REM This runs test and returns non-zero exit code when test fails.
test.exe -fail
set return_code=%ERRORLEVEL%
REM Now, assume test failed, and it returns exit code 4.
echo %return_code%
exit %return_code%
Or do an if
statement and return your own exit code.
REM This runs test and returns non-zero exit code when test fails.
test.exe -fail
IF NOT %ERRORLEVEL% == 0 (
echo %ERRORLEVEL%
exit 1
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论