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
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.
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
tonone
. More info on this here.Here's a modification of your
.gitlab-ci.yml
file to do all that: