if-statement - Gitlab-CI:有条件的 allow_failure

标签 if-statement gitlab-ci compiler-warnings

我最近开始为我的代码实现自动测试,我注意到 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 of true or false 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.

https://about.gitlab.com/images/13_8/allow_fail.png -- Control job status using exit codes

See Documentation and Issue.


如果您可以使用脚本的退出状态作为条件,这对于 allow_failure 来说就足够了。更具体。

关于if-statement - Gitlab-CI:有条件的 allow_failure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64263667/

相关文章:

kubernetes - 使用环境变量在 knative service.yaml 文件中设置值

Gitlab runner 无法使用来自 ~/.docker/config.json 的凭据进行身份验证

c++ - 使用 gcc 构建 C++ 的推荐 -W 标志

ios - 在 TableView Controller (didSelectRowAtIndexPath) 中设置整数值以用于 PList (iOS)

wordpress - 使用 if is_page() Wordpress 条件语句

node.js - GitLab CI 卡在正在运行的 NodeJS 服务器上

c++ - 有没有办法找到导致 Qt 中出现警告的行?

c++ - 将编译器选项应用于特定文件

java - Play框架: scala template, if语句问题

javascript - 当 if 语句为 true 时,else 语句仍在运行