git - 如何使用 gitlab-ci.yml 进行简单的 pull ?

标签 git gitlab gitlab-ci gitlab-ci-runner

每次我从本地项目向我的 gitlab 存储库执行 git push 时,在我的服务器项目中执行 git pull 的正确形式是什么?

这是我的 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

这是来自 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

它说“工作成功”但我的服务器还没有更新。

我的服务器是 DigitalOcean 中的一个 Droplet:安装了 LAMP 环境的 Ubuntu 20.04 (LTS) x64。我尝试 pull 的项目是用 PHP 编写的。

最佳答案

当前观察到的行为是预期的行为,因为 gitlab 运行的所有命令都在其自己的环境中,而不是在您的服务器上。

要实现预期的行为:

  • 了解在执行 git checkout 命令之前,您的环境中已经有开发/生产代码库,为了确认它,您可以在 git checkout 之前包含 ls -al 。因此,git checkout 和 git pull 是多余的,因为 only 配置确保您的管道只为那些特定的分支运行。
  • 您必须执行以下操作之一:
    1. 将您的文件从当前的 gitlab 环境同步到您的 digitalocean 服务器(使用 rsync)
    2. 从 digitalocean 服务器上的 gitlab 管道远程运行命令 git checkoutgit pull(Reference1Reference2)。
对于需要在部署前构建的代码库,建议使用

1。然而,对于您的简单用例 2 就足够了。

关于git - 如何使用 gitlab-ci.yml 进行简单的 pull ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67040793/

相关文章:

docker - GitLab 自动开发 : Dockerfile build-args

reactjs - 将 React 应用程序部署到 gitlab 页面后出现空白页面

python - 为什么 Windows 上的 gitpython 总是出现文件未找到的错误?

Git,提交时阅读最新的提交消息

git - 你如何删除远程 git branch "properly",也就是为所有用户更新远程分支列表?

gitlab - 如何为gitlab集成sourcetree

Git merge 冲突 (UU) : How do I resolve conflict without adding file to next commit?

Android:找不到或加载主类 org.gradle.wrapper.GradleWrapperMain

git - 由于 : failed to push some refs,无法将文件推送到 git

docker - Docker Dind:无法连接到Docker守护程序