How to run gitlab ci only when dir changed?

Published 05-04-2019 16:32:44

参考: https://gitlab.com/gitlab-org/gitlab-ce/issues/19813

当`db/migrate` 目录有变化的时候执行prod的测试脚本

test_prod_schema:
  stage: test
  script:
    - >
      if git diff HEAD~ --name-only|grep db/migrate; then
        cp config/database.prod-schema-mysql.yml config/database.yml
        bundle exec rails db:create
        mysql -h mysql -uroot -proot <<< "use shiji_prod; source db/tables_dump_April_28_2019.sql;"
        bundle exec rails db:migrate
      fi;