[英]How to do a simple pull with gitlab-ci.yml?
What is the correct form to do a git pull
in my server project everytime I do a git push to my gitlab repository from my local project?每次我从本地项目执行 git 推送到我的 gitlab 存储库时,执行git pull
入我的服务器项目的正确形式是什么?
This is my gitlab-ci.yml:这是我的 gitlab-ci.yml:
stages:
- test
- deploy
test:
stage: test
only:
- develop
- production
script:
- git checkout develop
- git pull
step-deploy-prod:
stage: deploy
only:
- production
script:
- git checkout production
- git pull
environment: production
when: manual
And this are the messages from the Gitlab CI/CD Jobs:这是来自 Gitlab CI/CD 作业的消息:
Running with gitlab-runner 13.9.0-rc2 (69c049fd)
on docker-auto-scale 72989761
feature flags: FF_GITLAB_REGISTRY_HELPER_IMAGE:true
Preparing the "docker+machine" executor
00:36
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:ad71c4982eb130f0dabcd6028201d00350863250b5a5cbc991adbf0c4e37b4f2 for ruby:2.5 with digest ruby@sha256:1cb06265c85952ececf5e4990b70abf3146ce798a670c50c1dd3380a6ba470d7 ...
Preparing environment
00:02
Running on runner-72989761-project-25613657-concurrent-0 via runner-72989761-srm-1618105481-ed6a658b...
Getting source from Git repository
00:05
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/ivanvaleraa/pos_v1/.git/
Created fresh repository.
Checking out eabdc2d3 as develop...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
Using docker image sha256:ad71c4982eb130f0dabcd6028201d00350863250b5a5cbc991adbf0c4e37b4f2 for ruby:2.5 with digest ruby@sha256:1cb06265c85952ececf5e4990b70abf3146ce798a670c50c1dd3380a6ba470d7 ...
$ git checkout develop
Switched to a new branch 'develop'
Branch 'develop' set up to track remote branch 'develop' from 'origin'.
$ git pull
From https://gitlab.com/ivanvaleraa/pos_v1
* [new branch] master -> origin/master
* [new branch] production -> origin/production
Already up to date.
Cleaning up file based variables
00:00
Job succeeded
It said "Job succeeded" but my server havent updated.它说“作业成功”,但我的服务器还没有更新。
My server is a Droplet in DigitalOcean: Ubuntu 20.04 (LTS) x64 with LAMP enviroment installed.我的服务器是 DigitalOcean 中的 Droplet:安装了 LAMP 环境的 Ubuntu 20.04 (LTS) x64。 The project I am trying to pull is in PHP.我要拉的项目在 PHP 中。
The current behavior observed is the expected one, as all the commands being run by gitlab is inside its own environment and not on your servers.当前观察到的行为是预期的行为,因为 gitlab 运行的所有命令都在其自己的环境中,而不是在您的服务器上。
To achieve the expected behaviour:要实现预期的行为:
git checkout
command, to confirm it you may include ls -al
before git checkout
.了解在git checkout
命令之前您的环境中已经有开发/生产代码库,以确认您可以在git checkout
之前包含ls -al
。 Therefore, git checkout and git pull are redundant, as only
configuration makes sure that your pipeline only runs for those specific branches.因此,git checkout 和 git pull 是多余的,因为only
配置才能确保您的管道仅针对这些特定分支运行。git checkout
and git pull
from gitlab pipeline on your digitalocean server ( Reference1 and Reference2 ).远程运行您的命令git checkout
和git pull
从您的 digitalocean 服务器上的 gitlab 管道( 参考1 和参考2)。1 is recommended for codebases that are required to be built before deployment.对于需要在部署之前构建的代码库,建议使用 1。 Yet for your simple usecase 2 is sufficient.然而,对于您的简单用例 2 就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.