1

我已经修改了我的 Gitlab CI/CD 当前流程,以使用 codeclimate 添加一个关于代码质量的阶段。我尝试尽可能地遵循 Gitlab 文档,但是我收到了关于配置模板的错误。

 .codeclimate.yml is not a valid location!

这是我的.gitlabci.yml文件的内容

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4

1 回答 1

1

模板是.codeclimate.yml您项目中的本地文件吗?如果是这样,请使用local 关键字指定本地 yaml 文件。

include:
  - local: .codeclimate.yml

或者

include:
  - local: '.codeclimate.yml'

编辑:阅读Gitlab 文档后,这不应该那么复杂,因为 codeclimate 插件已经集成在所有层中。

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

code_quality:
  artifacts:
    paths: [gl-code-quality-report.json]
于 2021-12-31T20:29:06.113 回答