Code Quality
Introduced in GitLab Starter 9.3.
With the help of GitLab CI/CD, you can analyze your source code quality using GitLab Code Quality. Code Quality uses Code Climate Engines, which are free and open source. Code Quality doesn’t require a Code Climate subscription.
Going a step further, GitLab can show the Code Quality report right in the merge request widget area:
Use cases
For instance, consider the following workflow:
- Your backend team member starts a new implementation for making a certain feature in your app faster
- With Code Quality reports, they analyze how their implementation is impacting the code quality
- The metrics show that their code degrade the quality in 10 points
- You ask a co-worker to help them with this modification
- They both work on the changes until Code Quality report displays no degradations, only improvements
- You approve the merge request and authorize its deployment to staging
- Once verified, their changes are deployed to production
How it works
First of all, you need to define a job in your .gitlab-ci.yml
file that generates the
Code Quality report artifact.
The Code Quality report artifact is a subset of the Code Climate spec. It must be a JSON file containing an array of objects with the following properties:
Name | Description |
---|---|
description |
A description of the code quality violation. |
fingerprint |
A unique fingerprint to identify the code quality violation. For example, an MD5 hash. |
location.path |
The relative path to the file containing the code quality violation. |
location.lines.begin |
The line on which the code quality violation occurred. |
Example:
[
{
"description": "'unused' is assigned a value but never used.",
"fingerprint": "7815696ecbf1c96e6894b779456d330e",
"location": {
"path": "lib/index.js",
"lines": {
"begin": 42
}
}
}
]
For more information on what the Code Quality job should look like, check the example on analyzing a project’s code quality.
GitLab then checks this report, compares the metrics between the source and target branches, and shows the information right on the merge request.
If multiple jobs in a pipeline generate a code quality artifact, only the artifact from the last created job (the job with the largest job ID) is used. To avoid confusion, configure only one job to generate a code quality artifact.
If the Code Quality report doesn’t have anything to compare to, no information
will be displayed in the merge request area. That is the case when you add the
Code Quality job in your .gitlab-ci.yml
for the very first time.
Consecutive merge requests will have something to compare to and the Code Quality
report will be shown properly.
Help and feedback
If there's something you don't like about this feature
To propose functionality that GitLab does not yet offer
To further help GitLab in shaping new features
If you didn't find what you were looking for
If you want help with something very specific to your use case, and can use some community support
POST ON GITLAB FORUM
If you have problems setting up or using this feature (depending on your GitLab subscription)
REQUEST SUPPORT
To view all GitLab tiers and features or to upgrade
If you want to try all features available in GitLab.com
If you want to try all features available in GitLab self-managed
If you spot an error or a need for improvement and would like to fix it yourself in a merge request
EDIT THIS PAGE
If you would like to suggest an improvement to this doc