1

I've modified my Gitlab CI/CD current process to add a stage about the code quality using codeclimate. I've tried to follow Gitlab doc as possible as I can, nevertheless I got an error about the configuration template.

 .codeclimate.yml is not a valid location!

Here is the content of my .gitlabci.yml file

include:
 - template: .codeclimate.yml

stages:
  - slack-start-prod
  - slack-start-staging
  - docker
  - test
  - code-quality
  - deploy-staging
  - deploy-prod
  - slack-end-prod
  - slack-end-staging
  - slack-failure

//////////////////////////////////////////////////////////

#------------------------------------------
# run tests on builded docker image
#------------------------------------------
test:
  stage: test
  image:
    name: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
  services:
    - name: mysql:5.7
      alias: mysql
    - name: redis:6
      alias: redis
  variables:
    MYSQL_DATABASE: xx
    MYSQL_ROOT_PASSWORD: xx
    MYSQL_USERNAME: xx
    MYSQL_HOST: xx
  artifacts:
    reports:
      junit: phpunit-report.xml
    expire_in: 10 minutes
    when: always
  before_script:
    - until $(nc -z -v -w1 mysql 3306);do echo Waiting for mysql to be ready... && sleep 5s;done
  script:
    - cp .env.test.example /var/www/html/.env
    - echo 'ok' | mysql --user="$MYSQL_USERNAME" --password="$MYSQL_ROOT_PASSWORD" --host="$MYSQL_HOST" --execute="CREATE DATABASE xx"
    - cd /var/www/html
    - php artisan migrate --force
    - php -dxdebug.mode=coverage vendor/bin/phpunit --configuration phpunit.xml --log-junit phpunit-report.xml --coverage-text --colors=never
    - cp phpunit-report.xml $CI_PROJECT_DIR/
  tags:
    - kubernetes
#------------------------------------------
# run code quality
#------------------------------------------
code-quality:
  stage: test
  services:
    - name: codeclimate/codeclimate-phpcodesniffer
      alias: codeclimate-phpcodesniffer
    - name: codeclimate/codeclimate-duplication
      alias: codeclimate-duplication
  image:
    name: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
  artifacts:
    paths: [gl-code-quality-report.json]
    reports:
      codequality: gl-code-quality-report.json
  script:
    - codeclimate analyze
    - cp gl-code-quality-report.json $CI_PROJECT_DIR/
  variables:
    REPORT_FORMAT: html
  tags:
    - kubernetes

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
KubiRoazhon
  • 1,759
  • 3
  • 22
  • 48

1 Answers1

1

Is the .codeclimate.yml template a local file in your project? If so, use the local keyword to specify a local yaml file.

include:
  - local: .codeclimate.yml

or

include:
  - local: '.codeclimate.yml'

Edit: After reading the Gitlab docs, this shouldn't be that complex since the codeclimate plugin is already integrated in all tiers.

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

code_quality:
  artifacts:
    paths: [gl-code-quality-report.json]
Aristu
  • 761
  • 3
  • 17
  • 30
  • I'm getting this error : jobs version config should implement a script: or a trigger: keyword – KubiRoazhon Jan 03 '22 at 09:22
  • Does your `.codeclimate.yml` template contain a `script` keyword? I'm not seeing it getting inherited by other pipelines in your question, just imported. This means the template managed to get imported, but there's nothing to run, since Gitlab Pipelines need an obligatory `script` keyword defined. – Aristu Jan 03 '22 at 10:46
  • BTW, I've edited my answer after reading Gitlab's docs, the codeclimate plugin is already integrated in all tiers. – Aristu Jan 03 '22 at 10:59
  • I've already followed exactly the doc, but still have the original problem :) – KubiRoazhon Jan 03 '22 at 15:09