Commit 45efd441 authored by Matija Čupić's avatar Matija Čupić

Update code quality documentation

parent c7db9929
# Analyze your project's Code Quality # Analyze your project's Code Quality
CAUTION: **Caution:** CAUTION: **Caution:**
The job definition shown below is supported on GitLab 10.4 and later versions. The job definition shown below is supported on GitLab 11.4 and later versions.
For earlier versions, use the [old job definition](#old-job-definition). For earlier versions, use the [old job definition](#old-job-definition).
CAUTION: **Caution:** CAUTION: **Caution:**
...@@ -16,7 +16,7 @@ and Docker. ...@@ -16,7 +16,7 @@ and Docker.
First, you need GitLab Runner with [docker-in-docker executor][dind]. First, you need GitLab Runner with [docker-in-docker executor][dind].
Once you set up the Runner, add a new job to `.gitlab-ci.yml`, called `code_quality`. Once you set up the Runner, add a new job to `.gitlab-ci.yml`.
```yaml ```yaml
code_quality: code_quality:
...@@ -34,22 +34,50 @@ code_quality: ...@@ -34,22 +34,50 @@ code_quality:
--volume /var/run/docker.sock:/var/run/docker.sock --volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts: artifacts:
paths: [gl-code-quality-report.json] reports:
codequality: [gl-code-quality-report.json]
``` ```
The above example will create a `code_quality` job in your CI/CD pipeline which The above example will create a `code_quality` job in your CI/CD pipeline which
will scan your source code for code quality issues. The report will be saved will scan your source code for code quality issues. The report will be saved
as an artifact that you can later download and analyze. as an artifact that you can later download and analyze.
TIP: **Tip:**
Starting with [GitLab Starter][ee] 11.4, this information will be automatically
extracted and shown right in the merge request widget. To do so, the CI/CD job
must have a codequality report artifact. Due to implementation limitations we
always take the latest codequality artifact available.
[Learn more on Code Quality in merge requests](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html).
TIP: **Tip:** TIP: **Tip:**
Starting with [GitLab Starter][ee] 9.3, this information will Starting with [GitLab Starter][ee] 9.3, this information will
be automatically extracted and shown right in the merge request widget. To do be automatically extracted and shown right in the merge request widget. To do
so, the CI/CD job must be named `code_quality` and the artifact path must be so, the CI/CD job must be named `code_quality` and the artifact path must be
`gl-code-quality-report.json`. `gl-code-quality-report.json`.
[Learn more on Code Quality in merge requests](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html).
## Old job definition ## Old job definition
For GitLab 11.3 and earlier, the job should look like:
```yaml
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]
```
For GitLab 10.3 and earlier, the job should look like: For GitLab 10.3 and earlier, the job should look like:
```yaml ```yaml
......
...@@ -27,19 +27,19 @@ For instance, consider the following workflow: ...@@ -27,19 +27,19 @@ For instance, consider the following workflow:
## How it works ## How it works
In order for the report to show in the merge request, you need to specify a In order for the report to show in the merge request, you need to specify a job
`code_quality` job (exact name) that will analyze the code and upload the resulting that will analyze the code and upload the resulting output JSON as a codequality
`gl-code-quality-report.json` as an artifact. GitLab will then check this file and show report artifact. GitLab will then check this file and show the information
the information inside the merge request. inside the merge request.
>**Note:** >**Note:**
If the Code Climate report doesn't have anything to compare to, no information If the Code Climate 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 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. 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 Consecutive merge requests will have something to compare to and the code quality
report will be shown properly. report will be shown properly.
For more information on how the `code_quality` job should look like, check the For more information on how the code quality job should look like, check the
example on [analyzing a project's code quality with Code Climate CLI][cc-docs]. example on [analyzing a project's code quality with Code Climate CLI][cc-docs].
CAUTION: **Caution:** CAUTION: **Caution:**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment