简体   繁体   中英

Gradle caching doesn't work with GitLab-CI

I'm trying to use the caching mechanism but it doesn't work, I have tried different attempt but none of them seems to work for me. The listed tasks take about both about 75sec on my machine and on gitlab ci about 5-6 Minutes where the runner is downloading the dependencies again and in every pipeline.

The question is how can I cache the downloaded deps with gitlab ci?

image: dockerregistry.my-image:1.0.0
variables:
  GIT_SUBMODULE_STRATEGY: normal
  GRADLE_USER_HOME: $CI_PROJECT_DIR/.gradle

cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

before_script:
  - echo `pwd`
  - echo `$CI_PROJECT_DIR`
  - rm -f  .gradle/caches/modules-2/modules-2.lock
  - rm -fr .gradle/caches/*/plugin-resolution/

build:
  stage: build
  script:
    - ./gradlew assemble

junit:
  stage: test
  script:
     - ./gradlew test

thanks

Update

Executor: Kubernetes
Gitlab Version: 11.0.x

Submodule path 'my-other-application': checked out 'fxxxx1'
Checking cache for default...
Successfully extracted cache

.........

Running after script...
$ echo "End CI"
End CI
Creating cache default...
.gradle/wrapper: found 222 matching files          
.gradle/caches: found 8474 matching files     

I'm using docker executor with this and is working:

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle

With docker the cache is stored in the container, so if i run something like docker system prune and clear not running containers the cache is lost.

I don't know how Kubernetes works, maybe the container get deleted at the end of execution.

-> https://gitlab.com/gitlab-org/gitlab-runner/issues/1906

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM