我最近开始为我的代码实现自动测试,我注意到 CI 没有捕捉到编译器的警告 - 即使有警告,测试也显示为成功。
我最初为编译器添加了一个标志以将警告转换为错误和 allow_failure=True
,但问题是编译器在第一个warning->error中停止,并没有经过整个编译。
然后我使用了解释的技巧here将警告写入文件,然后测试文件是否不为零:
- make 2> >(tee make.warnings)
- test ! -s make.warnings
整个编译完成后,如果有警告写入文件,这将给出错误 - 并使用 allow_failure=True
,这适用于我没有错误/警告的情况,但也适用于我有警告的情况。但是,如果我有真正的错误,这也会在 CI 中显示为警告,并且不会因为 allow_failure=True
而停止管道。 .我找不到
allow_failure=True
的方法取决于脚本中运行的某些内容(不创建新阶段)或使用某些条件(即文件是否为空)。有没有一种简单的方法可以做到这一点,我错过了?
最佳答案
由于本身没有条件,请查看 GitLab 13.8 (2021 年 1 月):
Control job status using exit codes
You can use the
allow_failure
keyword to prevent failed jobs from causing an entire pipeline to fail.Previously,
allow_failure
only accepted boolean values oftrue
orfalse
but we’ve made improvements in this release.Now you can use the
allow_failure
keyword to look for specific script exit codes.This gives you more flexibility and control over your pipelines, preventing failures based on the exit codes.
See Documentation and Issue.
如果您可以使用脚本的退出状态作为条件,这对于
allow_failure
来说就足够了。更具体。
关于if-statement - Gitlab-CI:有条件的 allow_failure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64263667/