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

前端 未结 4 1398
感情败类
感情败类 2020-12-14 16:25

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 e         


        
相关标签:
4条回答
  • 2020-12-14 16:35

    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)

    0 讨论(0)
  • 2020-12-14 16:44

    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
    
    0 讨论(0)
  • 2020-12-14 16:57

    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.

    0 讨论(0)
  • 2020-12-14 16:57

    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
    
    0 讨论(0)
提交回复
热议问题