Search code examples
gitlab-cigitlab-ci-runner

gitlab ci cache no matching files


I try to build apk with gitlab runner

When I build apk, I don't want download all build pacakage everytime

so i try to caching .gradle/caches and .gradle/wrappers

following is my gitlab-ci.yml

sdk_build_job
  image: myimage:latest
  stage: sdk-build
  script:
    ...
  cache:
    key: gradle-cache
      - /root/.gradle/caches
      - /root/.gradle/wrapper

but create gradle-cache always make an warning

Creating cache gradle-cache...
WARNING: /root/.gradle/caches: no matching files       
WARNING: /root/.gradle/wrapper: no matching files      
Archive is up to date!                             

I don't know why can't find caches and wrapper directory

When i into docker container and find the folders, there were well positioned

root@runner-3d9fa57b-project-4-concurrent-0:~/.gradle# pwd
/root/.gradle
root@runner-3d9fa57b-project-4-concurrent-0:~/.gradle# ls -al
total 28
drwxr-xr-x 7 root root 4096 Dec 28 02:21 .
drwx------ 1 root root 4096 Dec 28 02:19 ..
drwxr-xr-x 6 root root 4096 Dec 28 02:20 caches
drwxr-xr-x 3 root root 4096 Dec 28 02:19 daemon
drwxr-xr-x 4 root root 4096 Dec 28 02:19 native
drwxr-xr-x 2 root root 4096 Dec 28 02:21 workers
drwxr-xr-x 3 root root 4096 Dec 28 02:19 wrapper

Please help me.......


Solution

  • That is because cache only works for files and folders INSIDE your project. This is poorly documented on the GitLab website IMHO.

    So:

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

    Still only searches in:

    /home/user/yourproject/root/.gradle/caches
    /home/user/yourproject/root/.gradle/wrapper
    

    For R, I set R_LIBS_SITE to a local folder inside my project. This allowed me to reuse installed packages. Have a look here.