2

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     

 
Community
  • 1
  • 1
imalik8088
  • 1,501
  • 5
  • 21
  • 39
  • 1
    Caching in Gitlab CI can be a real pain ... Could you please edit your question to include: What do the logs say (typically in the beginning of each job) regarding caching? What type of executor (shell, vbox, ...) are you using? – Maximilian C. Sep 27 '18 at 21:25
  • @MaximilianC. I have updated the original post. The strange thing is that the job is extracting the cache but still it downloads the internet/intranet (nexus). – imalik8088 Sep 28 '18 at 07:37
  • Mhhh. I have not worked with this executor type (to know it's quirks) nor gradle ... In your before script, could you add something that gives you an idea about whether the folder is properly filled: e.g. listing all files https://stackoverflow.com/questions/2437452/how-to-get-the-list-of-files-in-a-directory-in-a-shell-script (obviously, this will be too much files to post them here :D) – Maximilian C. Sep 28 '18 at 08:48
  • Are you sure that before script is not deleting your cache? – Jakub Kania Oct 01 '18 at 17:40

1 Answers1

1

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

Petter
  • 318
  • 2
  • 13
  • The link is very good, thx for that! As far I understood I have to configure the cache in k8s within the runner it self see https://gitlab.com/gitlab-org/gitlab-runner/issues/1906#note_65897542 with every step the cache is been thrown away. – imalik8088 Oct 04 '18 at 13:36