GitLab deploy job fetches changes from git

2019-06-08 10:57发布

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.

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?

I have tried:

cache:
    untracked: true

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

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
1条回答
一纸荒年 Trace。
2楼-- · 2019-06-08 12:03

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.

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.

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

Using artifacts

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.

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.

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
查看更多
登录 后发表回答