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

How to detect compiler warnings in gitlab CI

在我们的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 或类似的东西。理想情况下,结果也应该在功能的合并请求中可见(如果可能的话阻止合并)。

我无法想象我是唯一一个试图实现这一目标的人,所以我可能找错了方向。我找到的 'best' 解决方案是以某种方式手动解析构建输出并生成 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 管道我正在寻找的状态。

似乎可以解决这种需求(例如,参见问题 "Add new CI state: has-warnings" https://gitlab.com/gitlab-org/gitlab-runner/issues/1224) has been to introduce the allow_failure 选项,这样一个作业就可以是编译本身,不是 允许失败(如果失败,则管道失败),另一项工作可以是检测此类警告, 允许失败(如果找到,则管道将不会失败)。

还请求了定义 warning regex in the .gitlab-ci.yml 的可能性,但目前还不存在。