2017-05-18 04:08:51 -04:00
|
|
|
# Analyze project code quality with Code Climate CLI
|
|
|
|
|
2017-06-04 23:26:34 -04:00
|
|
|
This example shows how to run [Code Climate CLI][cli] on your code by using
|
2017-05-18 04:08:51 -04:00
|
|
|
GitLab CI and Docker.
|
|
|
|
|
2017-06-04 23:26:34 -04:00
|
|
|
First, you need GitLab Runner with [docker-in-docker executor][dind].
|
2017-05-18 04:08:51 -04:00
|
|
|
|
2017-08-31 02:57:31 -04:00
|
|
|
Once you set up the Runner, add a new job to `.gitlab-ci.yml`, called `codequality`:
|
2017-05-18 04:08:51 -04:00
|
|
|
|
|
|
|
```yaml
|
2017-08-25 10:48:57 -04:00
|
|
|
codequality:
|
2017-05-18 04:08:51 -04:00
|
|
|
image: docker:latest
|
|
|
|
variables:
|
|
|
|
DOCKER_DRIVER: overlay
|
|
|
|
services:
|
|
|
|
- docker:dind
|
|
|
|
script:
|
|
|
|
- docker pull codeclimate/codeclimate
|
2018-01-09 09:18:13 -05:00
|
|
|
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate:0.69.0 init
|
|
|
|
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate:0.69.0 analyze -f json > codeclimate.json || true
|
2017-05-18 04:08:51 -04:00
|
|
|
artifacts:
|
|
|
|
paths: [codeclimate.json]
|
|
|
|
```
|
|
|
|
|
2017-08-25 10:48:57 -04:00
|
|
|
This will create a `codequality` job in your CI pipeline and will allow you to
|
2017-05-18 04:08:51 -04:00
|
|
|
download and analyze the report artifact in JSON format.
|
|
|
|
|
2017-06-04 23:26:34 -04:00
|
|
|
For GitLab [Enterprise Edition Starter][ee] users, this information can be automatically
|
|
|
|
extracted and shown right in the merge request widget. [Learn more on code quality
|
2017-06-14 02:22:47 -04:00
|
|
|
diffs in merge requests](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality_diff.html).
|
2017-06-04 23:26:34 -04:00
|
|
|
|
2017-05-18 04:08:51 -04:00
|
|
|
[cli]: https://github.com/codeclimate/codeclimate
|
2017-06-04 23:26:34 -04:00
|
|
|
[dind]: ../docker/using_docker_build.md#use-docker-in-docker-executor
|
|
|
|
[ee]: https://about.gitlab.com/gitlab-ee/
|