Gitlab code quality: where is the report?

Viewed 13292

On this project: https://gitlab.com/tyvain/parcoursup/tree/master

I have a code quality stage:

code_quality:
  stage: code_quality
  image: docker:stable
  variables:
    DOCKER_DRIVER: overlay2
  allow_failure: true
  services:
    - docker:stable-dind
  script:
    - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
    - docker run
        --env SOURCE_CODE="$PWD"
        --volume "$PWD":/code
        --volume /var/run/docker.sock:/var/run/docker.sock
        "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
  artifacts:
    paths: [gl-code-quality-report.json]

This stage always endup 'passed'. Logs: https://gitlab.com/tyvain/parcoursup/-/jobs/94665791

I doubt that my code is perfect, so there should be some code quality issues somewhere.

Where is the code quality report supposed to be output ?
What is this parameter: "paths: [gl-code-quality-report.json]" ?

5 Answers

2 problems here:

  • the report is only available for merge request in 'gitlab EE edition' (not free)
  • the report can be downloaded as a json file here: where to download artifacts

GitLab parses and displays the results in merge requests. It works by comparing to previous code quality results, so the first time you merge the job into master, you won't see anything. But, it should work on subsequent merge requests.

It's explained in a bit more detail here: Code Quality

This is old, but adding this here, in case someone else stumbles on it. I found the same issue (success, but no output) and the result was that the test was timing out. There's a default 900 second timeout on the codeclimate engine. The images that codeclimate uses are well over 1.5gb of data, so they take forever to download on a slow connection. When they timeout they return exit code 0, but no reports.

Verified by doing this locally:

docker run \
  --env CODECLIMATE_CODE=/path/to/my/code \
  --env CONTAINER_TIMEOUT_SECONDS=9000 \
  --volume /path/to/my/code:/code \
  --volume /tmp/cc:/tmp/cc \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --env CODECLIMATE_DEBUG=1 "codeclimate/codeclimate:0.83.0" \
  analyze -f json

Adding CONTAINER_TIMEOUT_SECONDS as an environment variable will allow you to surpass this, if timeout is your issue. I haven't gone further on using this in GitLab, as the documentation is lacking, and I only wanted checkstyle, not all the other stuff codequality comes with in GitLab, and the documentation wasn't clear on how to do that.

This has changed with GitLab 13.6 (November 2020):

Generate HTML reports for Code Quality

Code Quality reports provide you with a variety of information about code quality violations found on the current branch, but they are not in an easily readable format.

Now, this report is available as an .html file so you can more easily see the code quality violations in your project and determine the impact. You can even host the file on GitLab Pages for even easier reviewing!

Thanks for the contribution Vicken Simonian!

See Documentation and Issue.


See GitLab 13.11 (April 2021)

Code Quality violations sorted by severity

Running Code Quality scans on your Projects can find dozens to thousands of violations.

In the smaller view of the Merge Request widget, it can be hard to pinpoint the most critical issues to address first as you’re sorting through a large number of code quality violations.

Both the Code Quality Merge Request widget and the Full Code Quality Report now sort violations by Severity so that you can quickly identify the most important Code Quality violations to address.

https://about.gitlab.com/images/13_11/code-quality-sorted.png -- Code Quality violations sorted by severity

See Documentation and Issue.


GitLab 15.2 (July 2022) adds:

Merge request reports redesign

Merge request reports are an important part of code review, providing insights into the impact of changes and improvements to meet project standards.

Report widgets now all follow design guidelines for layout, hierarchy, and content sections, making them consistent, scannable, and utilitarian. These improvements make it easier for you to find actionable information in each report.

https://about.gitlab.com/images/15_2/create-merge-request-widget-redesign.png -- Merge request reports redesign

See Documentation and Epic.

Related