如何在gitlab CI中检测编译器警告 [英] How to detect compiler warnings in gitlab CI

查看:192
本文介绍了如何在gitlab CI中检测编译器警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In the steps of setting up CI builds on our gitlab server, I can't seem to find information on how to set up the detection of compiler warnings. Example build output:

[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")
 ^

但是构建结果是成功而不是 warning 或类似的结果.理想情况下,结果wuold也应在该功能的合并请求上可见(并在可能的情况下阻止合并).

However the build result is success instead of warning or something similar. Ideally the results wuold also be visible on the merge request on the feature (and block the merge if possible).

我无法想象我是唯一尝试实现这一目标的人,所以我可能朝错误的方向前进.我发现的最佳"解决方案是以某种方式手动解析构建输出并生成JUnit报告.

I can't imagine I'm the only one trying to achieve this, so I am probably looking in the wrong direction. The 'best' solution I found is to somehow manually parse the build output and generate a JUnit report.

在不使构建作业失败的情况下,我将如何做,因为我希望在发生编译器错误时作业会失败.

How would I go about doing this without allowing the build job to fail, since I would like the job to fail when compiler errors occur.

更新

对于以后遇到这个问题并代替最佳实践的任何人,这就是我解决的方法:

For anyone stumbling across this question later, and in lieu of a best practice, this is how I solved it:

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 到创建我一直在寻找的通过警告管道状态.

This stores the build output errors in make.error in the first stage, the next stage then queries that file for warnings and fails that stage with allow_failure: true to create the passed with warning pipeline status I was looking for.

推荐答案

似乎满足了这种需求的解决方案(例如,参见问题添加新的配置项状态:具有警告" allow_failure 选项,以便可以将一项工作编译为本身,不允许 失败(如果失败,则管道失败),另一项工作是检测允许 失败的警告(如果一个警告被发现,那么管道将不会失败).

It seems that the solution to such need (e.g., see the issue "Add new CI state: has-warnings" https://gitlab.com/gitlab-org/gitlab-runner/issues/1224) has been to introduce the allow_failure option so that one job can be the compilation itself, which is not allowed to fail (if it does, then the pipeline fails) and another job can be the detection of such warnings which is allowed to fail (if one is found then the pipeline will not fail).

还可以在.gitlab-ci.yml中定义警告正则表达式已被请求,但尚不存在.

Also the possibility of defining warning regex in the .gitlab-ci.yml has been requested but it does not exist yet.

这篇关于如何在gitlab CI中检测编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆