将Symfony主义迁移与Gitlab CI一起使用:GitLab CI将“无迁移”解释为错误

时间:2019-08-23 18:49:17

标签: symfony doctrine-orm gitlab-ci

我们在部署过程中使用Doctrine迁移捆绑包更新数据库。目前,我们正在切换到Gitlab-CI。

问题:由于命令php sf doctrine:migrations:diff的输出包含stderr,CI正在中止部署过程。

.gitlab-ci.yml的一部分:

deploy_live:
  type: deploy
  environment:
    name: live
    url: 1.2.3.4
  script:
      - ssh root@1.2.3.4 "cd /var/www/html/ && git pull origin master && exit"
      - ssh root@11.2.3.4 "cd /var/www/html/ && composer install -n && exit"
      - ssh root@1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:diff --env=prod && exit"
      - ssh root@1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:migrate -n --env=prod && exit"
      - 'ssh root@1.2.3.4 "cd /var/www/html/ && chown www-data:www-data . -R && exit"'
  only:
    - master

Gitlab CI的输出:

$ ssh root@1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:diff --env=prod && exit"
#!/usr/bin/env php

In NoChangesDetected.php line 13:

  No changes detected in your mapping information.  


doctrine:migrations:diff [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--editor-cmd [EDITOR-CMD]] [--filter-expression [FILTER-EXPRESSION]] [--formatted] [--line-length [LINE-LENGTH]] [--check-database-platform [CHECK-DATABASE-PLATFORM]] [--db DB] [--em [EM]] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

ERROR: Job failed: exit code 1

这可能是一个错误,但也许可以避免?

仅供参考:sf是指向bin/console的符号链接。

2 个答案:

答案 0 :(得分:1)

我刚刚找到了解决方法:

  1. 将直接从gitlab-ci.yml文件执行的命令移至script到Shell脚本deploy.sh
  2. 通过scp将该脚本移动到服务器

gitlab-ci.yml

deploy_live:
  type: deploy
  environment:
    name: live
    url: 1.2.3.4
  script:
      - scp deploy.sh root@1.2.3.4:/var/www/html/
      - ssh root@1.2.3.4 "cd /var/www/html/ && chmod +x deploy.sh && ./deploy.sh && exit"
  only:
    - master

deploy.sh

cd /var/www/html/
git add --all
git commit -m "changes"
git pull origin master

composer install -n
php sf doctrine:cache:clear-metadata --env=prod
php sf doctrine:migrations:diff --env=prod
php sf doctrine:migrations:migrate -n --env=prod

php sf cache:clear --env=prod

exit

答案 1 :(得分:0)