gcc - 如何在 gitlab CI 中检测编译器警告

标签 gcc gitlab-ci compiler-warnings

在我们的 gitlab 服务器上设置 CI 构建的步骤中,我似乎找不到有关如何设置编译器警告检测的信息。示例构建输出:

[100%] Building CXX object somefile.cpp.o
/home/gitlab-runner/builds/XXXXXXX/0/group/project/src/somefile.cpp:14:2: warning: #warning ("This is a warning to test gitlab") [-Wcpp]
 #warning("This is a warning to test gitlab")
 ^

但是构建结果是 success而不是 warning或类似的东西。理想情况下,结果也会在功能的合并请求中可见(并尽可能阻止合并)。

我无法想象我是唯一一个试图实现这一目标的人,所以我可能看错了方向。我发现的“最佳”解决方案是以某种方式手动解析构建输出并生成 JUnit 报告。

我将如何在不让构建作业失败的情况下执行此操作,因为我希望在发生编译器错误时作业失败。

更新

对于后来遇到这个问题的任何人,作为最佳实践的替代,我是这样解决它的:
stages:
  - build
  - check-warnings

shellinspector:
  stage: build
  script:
    - cmake -Bcmake-build -S.
    - make -C cmake-build > >(tee make.output) 2> >(tee make.error)
  artifacts:
    paths:
      - make.output
      - make.error
    expire_in: 1 week

analyse build:
  stage: check-warnings
  script:
    - "if [[ $(cat make.error | grep warning -i) ]]; then cat make.error; exit 1; fi"
  allow_failure: true

这会将构建输出错误存储在 make.error 中在第一阶段,下一阶段然后查询该文件以获取警告并在该阶段失败 allow_failure: true创建 passed with warning我正在寻找的管道状态。

最佳答案

似乎这种需求的解决方案(例如,请参阅问题“添加新 CI 状态:已警告”https://gitlab.com/gitlab-org/gitlab-runner/issues/1224)已经引入 allow_failure选项,以便一项作业可以是编译本身,不允许失败(如果失败,则管道失败),而另一项作业可以是检测此类允许失败的警告(如果找到,则管道不会失败)。

也可以定义 warning regex in the .gitlab-ci.yml已被请求,但尚不存在。

关于gcc - 如何在 gitlab CI 中检测编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59680450/

相关文章:

docker - CI脚本作业之前如何在推送时重建Docker镜像

c++ - 不执行任何操作且编译时带有 4 级警告的函数

postgresql - Gitlab CI with Docker images - Flask 微服务测试数据库

.net - .NET 中非 CLS 兼容代码的后果是什么?

c - 为什么在 glibc 中使用 crypt 会导致编译器警告?

linux - cygwin 中 WinMain@16 下的 undefined reference

objective-c - GNU Objective-C 运行时技巧

重定位 vector 表的C代码

macos - 在 OS X Yosemite 上构建 GCC-4.9.2

Gitlab CI - Composer 安装在私有(private)仓库上