debian-mirror-gitlab/doc/ci/examples/code_climate.md

43 lines
1.6 KiB
Markdown
Raw Normal View History

2017-09-10 17:25:29 +05:30
# Analyze project code quality with Code Climate CLI
This example shows how to run [Code Climate CLI][cli] on your code by using
GitLab CI and Docker.
First, you need GitLab Runner with [docker-in-docker executor][dind].
2018-03-17 18:26:18 +05:30
Once you set up the Runner, add a new job to `.gitlab-ci.yml`, called `codequality`:
2017-09-10 17:25:29 +05:30
```yaml
2018-03-17 18:26:18 +05:30
codequality:
2018-05-09 12:01:36 +05:30
image: docker:stable
2017-09-10 17:25:29 +05:30
variables:
2018-05-09 12:01:36 +05:30
DOCKER_DRIVER: overlay2
allow_failure: true
2017-09-10 17:25:29 +05:30
services:
2018-05-09 12:01:36 +05:30
- docker:stable-dind
2017-09-10 17:25:29 +05:30
script:
2018-03-27 19:54:05 +05:30
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
2018-05-09 12:01:36 +05:30
- 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
2017-09-10 17:25:29 +05:30
artifacts:
paths: [codeclimate.json]
```
2018-03-27 19:54:05 +05:30
The above example will create a `codequality` job in your CI/CD pipeline which
will scan your source code for code quality issues. The report will be saved
as an artifact that you can later download and analyze.
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
TIP: **Tip:**
Starting with [GitLab Starter][ee] 9.3, this information will
be automatically extracted and shown right in the merge request widget. To do
so, the CI/CD job must be named `codequality` and the artifact path must be
`codeclimate.json`.
[Learn more on code quality diffs in merge requests](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality_diff.html).
2017-09-10 17:25:29 +05:30
[cli]: https://github.com/codeclimate/codeclimate
[dind]: ../docker/using_docker_build.md#use-docker-in-docker-executor
2018-03-17 18:26:18 +05:30
[ee]: https://about.gitlab.com/products/