[英]Gitlab CI - Deploying via SSH and git pull origin develop will not execute
So I'm using a self-hosted GitLab instance trying to deploy my Laravel application.所以我正在使用一个自托管的 GitLab 实例来尝试部署我的 Laravel 应用程序。 I am using the v10+ GitLab runner on a SSH executor.我在 SSH 执行程序上使用 v10+ GitLab 运行程序。
Here is my .gitlab-ci.yml
:这是我的.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.如您所见,我使用 SSH 进入并执行这些操作。 Let me know if there's a cleaner way to write this .yml
file.让我知道是否有更.yml
方法来编写这个.yml
文件。
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?为什么我不能做 git pull? I uploaded .git
folder to the server as well.我也将.git
文件夹上传到服务器。
If I replace git pull origin develop
with git log
, the job is a success and I can see the latest git changes.如果我将git pull origin develop
替换为git log
,则作业成功,我可以看到最新的 git 更改。 Even now you can see the latest git commit.即使现在你也可以看到最新的 git commit。 What am I doing wrong?我究竟做错了什么?
You just need to throw in a stash
( How to ignore error on git pull about my local changes would be overwritten by merge? ).您只需要放入一个stash
( How to ignore error on git pull 关于我的本地更改将被合并覆盖? )。 If you don't mean to overwrite these changes, then throw in the pop
as well.如果您不想覆盖这些更改,那么也将pop
。
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.使用 Git 进行部署并不总是不合适的,但是您将这种部署方式自动化的点是您重新考虑它的点。 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. Dockerfiles,自动缩放启动配置,让你的 box cron 同步来自 GitLab 的工件存档(或托管一个 webhook 来做到这一点),只要不那么笨拙的方法,天空就是极限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.