Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.......

like image 749
fuzes Avatar asked Dec 28 '18 02:12

fuzes


2 Answers

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.

like image 190
MS Berends Avatar answered Oct 19 '22 11:10

MS Berends


I banged my head on the same issue.

MS Berends is partially right. Caching is supposed to work for files and folders only already within your project directory, see here: https://gitlab.com/gitlab-org/gitlab-ce/issues/4431

There were supposed to be an option of mounting the cache folder as a volume like

[[runners]]
  name = ""
  url = ""
  token = ""
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/root/.gradle:/root/.gradle"]
    shm_size = 0

But that does not work neither.

What I ended up doing is the following:

  1. In my .gitlab-ci.yaml, I set the GRADLE_USER_HOME to point on the already mapped cache volume like

    GRADLE_USER_HOME: "/cache/.gradle"
    
  2. Then I passed that gradle home variable to the ./gradlew like

    ./gradlew $GRADLE_ARGS_CI -g $GRADLE_USER_HOME testDebugUnitTest
    
  3. Notice the argument named $GRADLE_ARGS_CI. It is set to the following value

    GRADLE_ARGS_CI: "--no-build-cache --no-daemon --stacktrace"
    

The --no-build-cache is necessary if you don't want to reuse the build outputs from previous builds. The --no-daemon is a no brainer because the docker build environment is spawned for every build.

I was able to save 2.5 min on my build time with these changes.

like image 6
Hamady C. Avatar answered Oct 19 '22 11:10

Hamady C.