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

8.2 only supports per-job cache, and 8.3 will introduce "group" cache that serves among jobs according to @ayufan's comment in Possibility to cache folders in build directory (#97).

However, although I cannot be 100% sure, by quick digging the source code of gitlab-ci-muti-runner, docker executor doesn't seems to work with the cache functionality. Since a whole new container is created and destroyed in every job, the cache.tgz archive would no longer exist in the next build.

Errata:

The above description is incorrect due to testing in a misconfigured environment. By default, gitlab-ci-multi-runner creates a dedicated data volume container as a cache storage for each concurrent build. The cache container is mounted to directory /cache in the application container and those cache.tgz tarballs are placed under /cache by default. So caches are actually reusable among independent builds.

Updates 2015/12/11:

Just found out that "group" cache has already been implemented in gitlab-runner@7dc9524f6ef0144b3797fc07c9035f38a8ad0512, maybe not yet released and documented. You can enable it with

cache:
  paths:
    - doc/
  group: sharedcache

The result is one cache tarball being placed under path <namespace>/<repo>/sharedcache/ instead of two cache tarballs being placed separately under path <namespace>/<repo>/createcache/ and <namespace>/<repo>/testcache/.

Updates 2017/12/04:

"group" cache has been replaced by cache:key. Use the key key to make the cache share between jobs or git references. By default, a cache is shared between all jobs. So, simply write the following would do the job

cache:
  paths:
    - doc/

Checkout GitLab CI cache:key and gitlab-runner@d34f76f86a7c2fc4d399e9922175bcc614434016 for more information.

Cache dependencies in GitLab CI/CD, This extends `.gitlab-ci.yml` syntax to allow specifying caching files and If we do this is a next step to make build more sticky (use the same runner for the same � 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:

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

Allow to define cache in `.gitlab-ci.yml` (!1786) � Merge Requests , gitlab runner configured for 5 concurrent jobs Pipeline : dep > test_lint/test_unit on local njdBHAMf Using Docker executor with image node:8.2.1 . now at 49da7b3 Update .gitlab-ci.yml Checking out 49da7b35 as develop. Par défaut, gitlab-ci-multi-runner crée un conteneur de volume de données dédié comme un stockage de cache pour chaque construction concurrente. Le conteneur cache est monté dans le répertoire /cache dans le conteneur d'application et dans le cache.tgz les archives sont placées sous /cache par défaut. Donc les caches sont réellement

It seems it is not possible to cache container local files with shared runners. You have to put your files in e.g. the cache folder:

before_script:
  - export GRADLE_USER_HOME=/cache/.gradle

...

cache:
  paths:
    - $GRADLE_USER_HOME/caches/
    - $GRADLE_USER_HOME/wrapper/
    - $GRADLE_USER_HOME/build-cache/

Strictly it is not required to put the /cache folder as files to cache, because this happens automatically, but I leave it for clarity (also when I want to move the gradle cache)

[11.6.1] Cache not copy when two jobs are started at the , You want to use a cache for a shell runner? then just use a directory build types and trashed after the whole .gitlab-ci.yml scripts finished? with Gitlab 8.2. 1 and runner 0.7.2, a separate cache tarball is created for each job. By default, gitlab-ci-multi-runner creates a dedicated data volume container as a cache storage for each concurrent build. The cache container is mounted to directory /cache in the application container and those cache.tgz tarballs are placed under /cache by default. So caches are actually reusable among independent builds.

We found out, that is better to cache the whole .gradle-folder. This should be used only once per project. If k8s used for gitlab-runner, then you should turn the daemon off.

gitlab-ci.yaml:

variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false" # no gradle-daemon on k8s

# ...

buildJar:
  stage: build
  image: gradle:5.6.4-jdk11
  before_script:
    - export GRADLE_USER_HOME=`pwd`/.gradle
  script:
    - gradle assemble
  cache:
    key: "gradleCache"
    paths:
      - .gradle

Possibility to cache folders in build directory (#97) � Issues � GitLab , I have a job in YAML script that consists of compiling, testing and uploading the running gitlab 8.2.1 and runner 0.7.2, I have no success using cache for this� 8.2 wird nur pro Jobcache unterstützt, und 8.3 wird einen "Gruppen" -Cache einführen, der unter Jobs dient nach @ayufan's comment in Possibility to cache folders in build directory (#97).

Not to clean up between jobs (#280) � Issues � GitLab.org / gitlab , GitLab CI/CD pipelines are configured using a YAML file called .gitlab-ci.yml within image; services; stages; types; before_script; after_script; variables; cache� We have a server running gitlab and gitlab-runners on same machine. I've defined a runner as below [abc@xyz bin]# gitlab-ci-multi-runner register Running in system-mode.

GitLab CI/CD pipeline configuration reference, My .gitlab-ci.yml file has the following global cache definition cache: key: I use gitlab ci in production. I have a gitlab 8.2.1, How to use cache in .gitlab-ci.yml. gitlab 8.2.1, How to use cache in .gitlab-ci.yml. 0. How to run a gitlab-ci.yml job only on a tagged branch? 24. gitlab ci: Run build job when manual or when

Clearing the pipeline cache with Gitlab CI - gitlab - iOS, gitlab 8.2.1, How to use cache in .gitlab-ci.yml. Equivalent Maven example: image: maven:3-jdk-11 variables: MAVEN_CLI_OPTS: "--batch-mode"� I use gitlab-ci to test, compile and deploy a small golang application but the problem is that the stages take longer than necessary because they have to fetch all of the dependencies every time. How can I keep the golang dependencies between two stages (test and build)? This is part of my current gitlab-ci config:

Comments
  • Perhaps this is due to how you reduced, but please heed "Don’t mix the caching with passing artifacts between stages. Caching is not designed to pass artifacts between stages." docs.gitlab.com/ee//ci/caching/index.html#cache-vs-artifacts
  • CI linter says test:cache config contains unknown keys: group
  • @Kyslik It has been replaced by cache:key. Check out gitlab.com/gitlab-org/gitlab-runner/commit/… and docs.gitlab.com/ee/ci/yaml/#cache-key
  • Just a comment - it's much easier to read your answer if you finish each edit with a complete answer. There is an edit history, so we can see what you've changed. There's no need for headings for edits; just update the content so it reads clearly.
  • I used the config above but the gradle wrapper was still downloading the files into .gradle/wrapper. Maybe it's some other related issue.
  • I have to say I have seen the same results as @SailAvid. I also attempted to cache about every possible gradle directory that could exist from the first job (e.g. build) and all dependencies were getting pulled again in the second job.
  • Same here. When reading the file, it looks like we're setting GRADLE_USER_HOME to a path inside the build-folder (so we can cache it) and the cache seems to be created and applied on following jobs but gradle keeps downloading. Any new ideas on this?
  • Same happens to me, it saves the cache and applies it but Gradle is still downloading, any news on this?
  • Is the /cache documented somewhere? I've only seen docs mentioning cache:
  • I remember it reading it somewhere, maybe they changed the behavior and/or removed it from the docs?