簡體   English   中英

如何用 gitlab-ci.yml 做一個簡單的拉動?

[英]How to do a simple pull with gitlab-ci.yml?

每次我從本地項目執行 git 推送到我的 gitlab 存儲庫時,執行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。 我要拉的項目在 PHP 中。

當前觀察到的行為是預期的行為,因為 gitlab 運行的所有命令都在其自己的環境中,而不是在您的服務器上。

要實現預期的行為:

  • 了解在git checkout命令之前您的環境中已經有開發/生產代碼庫,以確認您可以在git checkout之前包含ls -al 因此,git checkout 和 git pull 是多余的,因為only配置才能確保您的管道僅針對這些特定分支運行。
  • 您必須執行以下操作之一:
    1. 將您的文件從當前 gitlab 環境同步到您的 digitalocean 服務器(使用rsync
    2. 遠程運行您的命令git checkoutgit pull從您的 digitalocean 服務器上的 gitlab 管道( 參考1 和參考2)。

對於需要在部署之前構建的代碼庫,建議使用 1。 然而,對於您的簡單用例 2 就足夠了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM