user4144415
user4144415

Reputation:

Using Symfony Doctrine Migrations with Gitlab CI: GitLab CI interprets "Nothing to migrate" as error

We are using the Doctrine migrations bundle for update database in our deployment process. Currently, we are switching to Gitlab-CI.

The problem: The CI is aborting the deployment process because the output of command php sf doctrine:migrations:diff contains stderr.

The part of our .gitlab-ci.yml:

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

Output of Gitlab CI:

$ ssh [email protected] "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

This may be a bug, but maybe it can be circumvented?

FYI: sf is a symlink to bin/console.

Upvotes: 0

Views: 2033

Answers (2)

user4144415
user4144415

Reputation:

I just found a solution:

  1. move the commands excecuted directly from the gitlab-ci.yml file unter script to an shell script deploy.sh
  2. move this script via scp to the server

gitlab-ci.yml

deploy_live:
  type: deploy
  environment:
    name: live
    url: 1.2.3.4
  script:
      - scp deploy.sh [email protected]:/var/www/html/
      - ssh [email protected] "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

Upvotes: 1

Related Questions