1

So I'm using a self-hosted GitLab instance trying to deploy my Laravel application. I am using the v10+ GitLab runner on a SSH executor.

Here is my .gitlab-ci.yml:

stages:
  - deploy

deploy_develop:
   stage: deploy
   before_script:
     - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
     - eval $(ssh-agent -s)
     - ssh-add <(echo "$SSH_PRIVATE_KEY")
     - mkdir -p ~/.ssh
     - ssh-keyscan beta.beethovenworld.com > ~/.ssh/known_hosts
   script:
     - ssh -t nn2@beta.beethovenworld.com "chmod 400 ~/.ssh/id_rsa && cd /var/www/html && git pull origin develop -f && composer install --no-interaction --optimize-autoloader && php artisan key:generate && php artisan optimize && php artisan config:cache && php artisan route:cache && php artisan migrate"
   environment:
     name: beta
     url: https://beta.beethovenworld.com
   only:
     - develop

As you can see, I am using SSH to go in and perform those actions. Let me know if there's a cleaner way to write this .yml file.

The error:

From gitlab.beethovenworld.com:nn2/beethovenworld
 * branch            develop    -> FETCH_HEAD
   3c3ebf7..37f47cf  develop    -> origin/develop
error: Your local changes to the following files would be overwritten by merge:
    resources/views/layouts/composer/manage.blade.php
Please, commit your changes or stash them before you can merge.
Aborting
Updating b4422e8..37f47cf
ERROR: Job failed: exit code 1

Why can I not do a git pull? I uploaded .git folder to the server as well.

If I replace git pull origin develop with git log, the job is a success and I can see the latest git changes. Even now you can see the latest git commit. What am I doing wrong?

test
  • 17,706
  • 64
  • 171
  • 244

1 Answers1

1

You just need to throw in a stash (How to ignore error on git pull about my local changes would be overwritten by merge?). If you don't mean to overwrite these changes, then throw in the pop as well.

PS. I strongly recommend revising the entire strategy. Deploying using Git is not always inappropriate, but the point where you automate that style of deployment is the point you reconsider it. Dockerfiles, autoscaling launch configurations, having your box cron sync the artifact archive from GitLab (or host a webhook to do that), the sky's the limit as far as less clunky approaches.

nik.shornikov
  • 1,869
  • 1
  • 17
  • 21