Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab 8.2.1, How to use cache in .gitlab-ci.yml

I'm trying to use 'cache' in .gitlab-ci.yml (http://doc.gitlab.com/ce/ci/yaml/README.html#cache). My gitlab version is 8.2.1 and my Runner is:

$ docker exec -it gitlab-runner gitlab-runner -v  gitlab-runner version 0.7.2 (998cf5d) 

So according to the doc, everything is up to date, but I'm unable to use the cache ;-(. All my files are always deleted. Am I doing something wrong?

A cache archive is created, but not passed to the next jobs.

Here is my .gitlab-ci.yml

$ cat .gitlab-ci.yml     stages:     - createcache     - testcache      createcache:       type: createcache       cache:         untracked: true         paths:           - doc/       script:         - touch doc/cache.txt      testcache:       type: testcache       cache:         untracked: true         paths:           - doc/       script:         - find .         - ls doc/cache.txt 

Output of the job 'createcache'

Running on runner-141d90d4-project-2-concurrent-0 via 849d416b5994... Fetching changes... HEAD is now at 2ffbadb MUST BE REVERTED [...] $ touch doc/cache.txt [...] Archiving cache... INFO[0000] Creating archive cache.tgz ...               INFO[0000] Done!                                          Build succeeded. 

Output of the job 'testcache'

Running on runner-141d90d4-project-2-concurrent-0 via 849d416b5994... Fetching changes... Removing doc/cache.txt [...] $ ls doc/cache.txt ls: cannot access doc/cache.txt: No such file or directory  ERROR: Build failed with: exit code 1 

My workaround

My workaround is to manually untar what's in the /cache directory ... I'm pretty sure that's not the correct way to use cache ...

$ cat .gitlab-ci.yml     stages:     - build     - test     - deploy      image: ubuntu:latest      before_script:       - export CACHE_FILE=`echo ${CI_PROJECT_DIR}/createcache/${CI_BUILD_REF_NAME}/cache.tgz | sed -e "s|/builds|/cache|"`      createcache:       type: build       cache:         untracked: true         paths:           - doc/       script:         - find . | grep -v ".git"         - mkdir -p doc         - touch doc/cache.txt      testcache:       type: test       script:         - env         - find . | grep -v ".git"         - tar xvzf ${CACHE_FILE}         - ls doc/cache.txt 
like image 856
delanne Avatar asked Nov 26 '15 13:11

delanne


People also ask

What is cache in GitLab CI Yml?

A cache is one or more files a job downloads and saves. Subsequent jobs that use the same cache don't have to download the files again, so they execute more quickly. To learn how to define the cache in your . gitlab-ci. yml file, see the cache reference.

Where is GitLab CI cache stored?

By default, they are stored locally in the machine where the Runner is installed and depends on the type of the executor. Locally, stored under the gitlab-runner user's home directory: /home/gitlab-runner/cache/<user>/<project>/<cache-key>/cache. zip .

How does GitLab CI Yml work?

gitlab-ci. yml file to your repository, GitLab detects it and an application called GitLab Runner runs the scripts defined in the jobs. In this example, the build-code-job job in the build stage runs first. It outputs the Ruby version the job is using, then runs rake to build project files.

Where is GitLab runner config file?

You can find the config. toml file in: /etc/gitlab-runner/ on *nix systems when GitLab Runner is executed as root (this is also the path for service configuration)


1 Answers

https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/327

image: java:openjdk-8-jdk  before_script:     - export GRADLE_USER_HOME=`pwd`/.gradle  cache:   paths:     - .gradle/wrapper     - .gradle/caches  build:   stage: build   script:      - ./gradlew assemble  test:   stage: test   script:      - ./gradlew check 
like image 80
wcc526 Avatar answered Oct 19 '22 01:10

wcc526