Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeClimate report in GitLab for c++ not showing

I am trying to activate the code climate report for merge requests pipelines in GitLab. The CodeClimate analyser is running but there are not shows any warnings when I add some bad code. There might be some configuration which I have missed.

I have added the following to my .gitlab-ci.yml file in the project rot folder:

include:
    - template: Code-Quality.gitlab-ci.yml

And I have added the .codeclimate.yml file looks like this:

plugins:
  cppcheck:
    enabled: true
    config:
      check: all
      language: c++
      stds:
        - c++14
        - c++17

The build job completes with the following lines at the end of the log:

f47a75dcba39: Pull complete
Digest: sha256:c8afb8c2037f7b9c5c9ae198aff00b1cf80db11d3591fbe89dfb3c69192663f1
Status: Downloaded newer image for codeclimate/codeclimate:0.72.0
WARNING: A new version (v0.85.3) is available. Upgrade instructions are available at: https://github.com/codeclimate/codeclimate#packages
Uploading artifacts...
gl-code-quality-report.json: found 1 matching files 
Uploading artifacts to coordinator... ok            id=227197201 responseStatus=201 Created token=4xyzSXzN
Job succeeded

What could be wrong here, since the merge request doesn't show any CodeClimate report?

In GitLab I have created one merge request with the configuration change (merging into master). And one merge request with some bad code, based on the first merge request with the configuration (merging into master).

The bad code:

int non_used_int;

int non_initialized_int;

int dummy = non_initialized_int;





// empty for loop
for (int i=0; i<100; i++) {

}

And a final note: I am using the shared GitLab runners provided by GitLab.

Guides I have followed:

  • https://docs.gitlab.com/ee/ci/examples/code_quality.html
  • https://docs.codeclimate.com/docs/cppcheck
like image 912
7heViking Avatar asked Oct 15 '22 14:10

7heViking


1 Answers

[TLDR SCROLL DOWN TO SOLUTION]

you have to gain more control on your gitlab.yml file the best way to do so is by installing the gitlab-runner locally

  • Install GitLab Runner

  • Install Docker

after your gitlab-runner and docker are properly installed on your local machine

run it locally on your repository (you have to be inside your repository folder in the same path as .gitlab.yml file) start with a minimal .gitlab.yml file

the command to run locally is

sudo gitlab-runner exec docker <Task-Name>

for example lets take this minimal gitlab.yml file

image: walberla/cppcheck

cppcheck:
  script:
    - cppcheck --error-exitcode=1 . 

the command will be

sudo gitlab-runner exec docker cppcheck

and the output will look like this :

enter image description here

now if everything works fine to follow the gitlab pipeline output for example i made a simple gitlab repo only containing your example file and gitlab.yml

https://gitlab.com/Naor-Tedgi/cpp-ci-runner/-/jobs/235981732

now we gain control on all the process you could see exactly what is going inside the ci and run the same process locally for example in the pipeline the image they using is docker:stable-did after runing the same steps you will understand what you are missing

keep in mind that because you are using docker in docker you will need to add --docker-privileged

 sudo gitlab-runner exec docker <Task-Name> --docker-privileged

[UPDATE! 20/06/19]

after our chat talk, and further investigation I created a simple example using code quality and the same gitlab.yml as mention above an got the same problem

https://gitlab.com/Naor-Tedgi/cpp-ci-runner/-/jobs/235981732

enter image description here

artifacts links [404] : https://gitlab.com/Naor-Tedgi/cpp-ci-runner/-/jobs/235981732/artifacts/keep

we found out there is an open issue with gitlab code quality artifacts since yesterday

Code Quality no 'Download' option and 'Keep' results in 404

https://gitlab.com/gitlab-org/gitlab-ee/issues/12274

and need to follow up this thread for more information

[SOLUTION]

7heviking

after more forth investigation of the template Code-Quality.gitlab-ci.yml

in the last commit from 6 days ago that changes this file, they change the paths property to reports

enter image description here

as shown here

https://gitlab.com/gitlab-org/gitlab-ee/commit/f0773d9ec8628e301c5a673ff7b7c2193569395d

taking the previous file with the paths artifacts fix the problem with the 404

steps for fixing the issue:

  • wait for Gitlab To fix this
  • or you can use codeclimate without the template file as i used in my example project

https://gitlab.com/Naor-Tedgi/cpp-ci-runner/blob/master/.gitlab-ci.yml

this is the result of how it should look after uploading artifacts works

https://gitlab.com/Naor-Tedgi/cpp-ci-runner/-/jobs/236205051

like image 150
Naor Tedgi Avatar answered Oct 23 '22 22:10

Naor Tedgi