首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >gitlab-ci yaml文件不会在-1返回失败

gitlab-ci yaml文件不会在-1返回失败
EN

Stack Overflow用户
提问于 2020-09-30 19:01:05
回答 1查看 60关注 0票数 0

我用一个简单的脚本结束了我的测试步骤,该脚本扫描一个pytest output.log,如果失败,应该以-1退出,这样作业就会变成红色而不是绿色:

代码语言:javascript
运行
复制
  scripts:
    - lots of test steps
    - bash -c -l "python bin/status.py --statusfile=output.log; exit $?"

但是gitlab-ci-runner返回0:

代码语言:javascript
运行
复制
20200930123055|ERROR|bin/status.py:53|failed in line:173 
'========================= 2 failed, 5 passed in 16.91s =========================' so returning -1 to shell
Uploading artifacts for successful job
00:01
Uploading artifacts...
output.log: found 1 matching files and directories 
Uploading artifacts as "archive" to coordinator... ok  id=2750517 responseStatus=201 Created token=5Gh42zsB
Job succeeded

程序正在返回正确的退出代码:

代码语言:javascript
运行
复制
python.exe .\bin\status.py --statusfile=C:\users\mobj\Downloads\output.log 
20200930124542|ERROR|.\bin\status.py:53|failed in line:99 '=================== 1 failed, 5 passed, 1 skipped in 16.20s ====================' so returning -1 to shell
$?
False
python.exe .\bin\status.py --statusfile=C:\users\mobj\Downloads\output2.log 
$?
True

我尝试在sh中使用bin/status.py --statusfile=output.log,但是找不到这个抱怨文件。

EN

回答 1

Stack Overflow用户

发布于 2020-09-30 20:33:39

我发现了这个错误,原来bash包装中的;exit $?只返回到当前实例

代码语言:javascript
运行
复制
$ /bin/bash -c -l "./bin/status.py --statusfile=/mnt/c/Users/mobj/Downloads/output.log --debug; exit $?"
20200930142836|ERROR|./bin/status.py:53|failed in line:99 '=================== 1 failed, 5 passed, 1 skipped in 16.20s ====================' so returning -1 to shell
$ echo $?
0

因此,只需删除;exit $?即可使其正确:

代码语言:javascript
运行
复制
 /bin/bash -c -l "./bin/status.py --statusfile=/mnt/c/Users/mobj/Downloads/output.log --debug"
20200930142754|ERROR|./bin/status.py:53|failed in line:99 '=================== 1 failed, 5 passed, 1 skipped in 16.20s ====================' so returning -1 to shell
$ echo $?
255
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64136190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档