Tyvain
Tyvain

Reputation: 2750

Gitlab ci with code quality: This GitLab CI configuration is invalid

My ci configuration isn't working with code quality stage:

image: maven:latest

stages:
  - code_quality
  - build

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]

build:
  stage: build
  script:
    - mvn compile

Source example is here: https://gitlab.com/tyvain/mvn-ci-test/blob/master/.gitlab-ci.yml

I cannot make it work with official gitlab example for code quality: https://docs.gitlab.com/ee/ci/examples/code_quality.html

The error is : " This GitLab CI configuration is invalid: code_quality job: stage parameter should be code_quality, build"

Upvotes: 2

Views: 7128

Answers (2)

Michael Laffargue
Michael Laffargue

Reputation: 10294

Could be worthy to note that if you have a .gitlab-cy.yml file including 2 others, the stages part should be added to the main file.

Example :

Main:

stages:
  - build
  - test
  - analysis

include:
  - local: '/FRONTEND/.gitlab-ci.yml'
  - local: '/SERVER/.gitlab-ci.yml'

Why?

Because if you put stages in each file, only one will be used (the last one for me) which may not have the same stages as the other. And so you'll have that type of error job: stage parameter should be.

Upvotes: 1

S.K.
S.K.

Reputation: 3677

code_quality stage is missing a stage parameter. Include that as below:

code_quality:
  stage: code_quality
  image: docker:stable
  ...

Upvotes: 2

Related Questions