9

Today, while trying to setup CodeQuality in my .gitlab-ci.yml (on gitlab-ee 11.10, gitlab-runner 11.10) I encountered the following issue:

First thing the GitLab documentation tells you is it is possible to set this with help of a DockerInDocker gitlab-runner and a single configuration line:

include:
  - template: Code-Quality.gitlab-ci.yml

There is also disclaimer that this is supported in gitlab 11.11 or later, which is strange because as of April 23rd 2019, the latest version is 11.10. Not sure if this a typo or if they publish documentation before the releases are actually available.

I tried following this instructions but many things are unclear:

  1. I realized that the include statement should be added after the stages definition for the syntax check to pass.

  2. A code_quality job showed up and passed:


(source: cozyo.io)

However, later I learned from this answer that I need to create a .codeclimate.yml file and somehow add it .gitlab-ci.yml. That answer shares two links that can be used to understand how to work with CodeClimate but I'm haven't figured a way to add to gitlab-ci.yml. I found some example in this gitlab related page BUT this is not using the include statement described in the docs.

  1. I'm unable to find the report of the code_quaity job that passed. In this answer someone pointed out that the report is only available for download on the merge request for gitlab-ee. However this is not practical since then devs would have to start spamming mock merge request just to see if they code suffered down grades.

The gitlab-ci.yml I use looks something like this:

image: docker:stable

variables:
  ARTEFACT: my_app
  VERSION: 0.1
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2

services:
  - docker:dind

before_script:
  - docker info

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - docker build -t $ARTEFACT:$VERSION-DEV .

test:
  stage: test
  script:
    - docker run --rm --env MODE=DEV $ARTEFACT:$VERSION-DEV ./my_test.sh

include:
  - template: Code-Quality.gitlab-ci.yml

Ideally, this should be a simple as figuring out how to use CodeClimate for python applications and then adding its configuration to the repo and referencing in gitlab-ci.yml correct? But how to make the reference. Is there any clear documentation available somewhere?

EDIT: I now know that jobs are independent and that I should modify the build stage in the .gitlab-ci.yml above to push the build image somewhere other jobs can pull from. Still this doesn't help to solve the CodeQuality problem I think.

Community
  • 1
  • 1
Mario
  • 151
  • 2
  • 11

1 Answers1

0

First, yes, GitLab often has docs for features of the coming release before the official release. The docs often apply to pre-release versions which are often running on GitLab.com.

The docs could probably be clearer, so I encourage you to file an issue with specifics on how the docs could be improved or even submit a MR if you feel comfortable with that.

Do note that code quality is a paid feature so requires a Starter license for a self-managed install (or Bronze on GitLab.com).

The code quality process will store information based on the first run in a codeclimate.json file. This is merely reference for future runs and is not the code quality report itself. Upon subsequent runs, the code climate report will be viewable in the Merge Request which kicked off the pipeline.

In order for the code climate report to appear in the Merge Request, the following conditions must be met:

  • You've defined a job in your .gitlab-ci.yml which produces the Code Quality report artifact
  • The job must not be the first run. 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.
  • A code error must be present. There has to be a degradation/error in your code as this is what will be displayed in the merge request page. If the code is correct there will be nothing displayed.
  • The .json file must not be too large. There is an existing issue which prevents the code report from displaying when the related .json file is very large.
Arty-chan
  • 2,572
  • 1
  • 19
  • 25