GitLab部署作业从git获取更改 [英] GitLab deploy job fetches changes from git

查看:90
本文介绍了GitLab部署作业从git获取更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,部署脚本使用了构建作业的结果,但是我看到在我的部署作业中,GitLab CI重新获取了上一次提交的所有更改,还删除了由构建作业生成的所有文件.我正在使用Shell Executor.

In my project, the deploy script uses the results of the build job, but I see that on my deploy job GitLab CI refetches all changes from the last commit and also removes all files produced by the build job. I am using the Shell Executor.

是否有一种方法可以防止GitLab CI在部署作业上执行此操作,以便我的部署可以从我的构建作业停止的地方继续进行?

Is there a way to prevent GitLab CI from doing this on the deploy job, so that my deploy can just continue from where my build job left off?

我尝试过:

cache:
    untracked: true

在我的部署工作上,但似乎没有任何作用

on my deploy job, but it did not seem to make any difference

我完整的.gitlab-ci.yml是:

my complete .gitlab-ci.yml is:

before_script:
  - sudo apt-get -y install default-jdk
  - sudo add-apt-repository -y ppa:cwchien/gradle
  - sudo apt-get -y update
  - sudo apt-get -y install gradle
  - curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
  - sudo apt-get install -y nodejs
  - sudo npm install -g pm2

stages:
  - build
  - test
  - deploy

after_script:

jobBuild:
  stage: build
  script:
    - ( cd my-lib; gradle build assemble)
  only:
    - master

jobDeploy:
  before_script:

  stage: deploy
  cache:
    untracked: true

  script:
    - <some shell scripts>
  only:
    - master

推荐答案

有关Gitlab CI的更多信息

More info on Gitlab CI cache

First, since it's the files from the build job you want to cache, you may want to add the cache rule to jobBuild. You could even define the cache globally by defining it outside a job.

缓存机制的问题在于它是一种尽力而为的系统,这意味着缓存可能并不总是可用.

The problem with the caching mechanism is that it's a best effort system, meaning the cache might not always be available.

缓存是尽最大努力提供的,因此不要指望 缓存将始终存在.有关实施细节,请检查 亚搏体育app Runner.

The cache is provided on a best-effort basis, so don't expect that the cache will be always present. For implementation details, please check GitLab Runner.

如果您想要将将构建文件从一项工作转移到另一项工作的100%的时间,则需要使用

If you want something that will transfer built files from one job to another 100% of the time, you need to use artifcats.

Gitlab CI将允许您定义一组文件和/或文件夹,以在工作结束时捆绑到工件中.如果您指定对第一个作业的依赖性,那么该工件就可以在以后的作业中使用.

Gitlab CI will let you define a set of files and/or folders to bundle into an artifact at the end of a job. That artifact will then be available to use in jobs of later stages provided you specify a dependency on the first job.

如果您不想在部署阶段获取git repo,可以将GIT_STRATEGY设置为none. 此处.

If you don't want to fetch the git repo in the deploy stage, you can set your GIT_STRATEGY to none. More info on this here.

这是对.gitlab-ci.yml文件的修改,可以完成所有操作:

Here's a modification of your .gitlab-ci.yml file to do all that:

before_script:
  - sudo apt-get -y install default-jdk
  - sudo add-apt-repository -y ppa:cwchien/gradle
  - sudo apt-get -y update
  - sudo apt-get -y install gradle
  - curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
  - sudo apt-get install -y nodejs
  - sudo npm install -g pm2

stages:
  - build
  - test
  - deploy

after_script:

jobBuild:
  stage: build
  script:
    - ( cd my-lib; gradle build assemble)
  only:
    - master
  artifacts:
    paths:
      - path/to/folder/containing/build/files # for example my-lib

jobDeploy:
  before_script:
  stage: deploy
  variables:
    GIT_STRATEGY: none
  dependencies:
    - jobBuild
  script:
    - cd path/to/folder/containing/build/files # for example my-lib
    - <some shell scripts>
  only:
    - master

这篇关于GitLab部署作业从git获取更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆