Template file is not a valid location in Gitlab CI/CD

1.3k Views Asked by At

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1

There are 1 best solutions below

4
Aristu On

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]