Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab Runner cache for Gradle is not working

I'm using GitLab Runner as CI to build an Android project however the cache is not working.

Here's my .gitlab-ci.yml. It was modified from https://gist.github.com/daicham/5ac8461b8b49385244aa0977638c3420.

image: runmymind/docker-android-sdk:latest
variables:
  GRADLE_USER_HOME: $CI_PROJECT_DIR/.gradle
stages:
  - build
debug:
  stage: build
  script:
    - set +e
    - du -sh $CI_PROJECT_DIR/.gradle/wrapper
    - du -sh $CI_PROJECT_DIR/.gradle/caches
    - set -e
    - ./gradlew assembleDebug
    - mkdir artifacts
    - cp mobile/build/outputs/apk/*.apk artifacts/
    - cp wear/build/outputs/apk/*.apk artifacts/
  cache:
    paths:
      - .gradle/wrapper/
      - .gradle/caches/
      - build/
      - mobile/build/
      - wear/build/
  artifacts:
    name: "project_${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}"
    expire_in: 2 weeks
    paths:
      - artifacts/

And the log:

Running with gitlab-ci-multi-runner 9.0.0 (08a9e6f)
Using Docker executor with image runmymind/docker-android-sdk:latest ...
Using docker image sha256:d696fa13188c8d2d121c86cf526201b363c1e34ee7b163d6ce1ab1718f91a5e6 ID=sha256:d696fa13188c8d2d121c86cf526201b363c1e34ee7b163d6ce1ab1718f91a5e6 for predefined container...
Pulling docker image runmymind/docker-android-sdk:latest ...
Using docker image runmymind/docker-android-sdk:latest ID=sha256:474ac98077a496f2f71aa22ce4eebcea966c2960a061d4a59babe81ff007009b for build container...
Running on runner-8ce5d03c-project-72-concurrent-0 via outrage...
Cloning repository...
Cloning into '/builds/User/android-project'...
Checking out 015d01d0 as master...
Skipping Git submodules setup
Checking cache for default...
Successfully extracted cache
$ set +e
$ du -sh $CI_PROJECT_DIR/.gradle/wrapper
du: cannot access '/builds/User/android-project/.gradle/wrapper': No such file or directory
$ du -sh $CI_PROJECT_DIR/.gradle/caches
du: cannot access '/builds/User/android-project/.gradle/caches': No such file or directory
$ set -e
$ ./gradlew assembleDebug
Downloading https://services.gradle.org/distributions/gradle-3.4.1-all.zip
Unzipping /builds/User/android-project/.gradle/wrapper/dists/gradle-3.4.1-all/c3ib5obfnqr0no9szq6qc17do/gradle-3.4.1-all.zip to /builds/User/android-project/.gradle/wrapper/dists/gradle-3.4.1-all/c3ib5obfnqr0no9szq6qc17do
Set executable permissions for: /builds/User/android-project/.gradle/wrapper/dists/gradle-3.4.1-all/c3ib5obfnqr0no9szq6qc17do/gradle-3.4.1/bin/gradle
Starting a Gradle Daemon (subsequent builds will be faster)
Download https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.0/gradle-2.3.0.pom
(more downloads)

I have also tried using gradle argument to set gradle user home, aggressively specifying .gradle/ for cache, etc, but none of them worked.

Any ideas?

like image 915
Frederick Zhang Avatar asked May 22 '26 08:05

Frederick Zhang


1 Answers

If you use Gitlab < 9.0,you add to specify the cache has to be shared among different pipelines.

Try to add key: $CI_PROJECT_NAME under cache:

image: runmymind/docker-android-sdk:latest
variables:
  GRADLE_USER_HOME: $CI_PROJECT_DIR/.gradle
stages:
  - build
debug:
  stage: build
  script:
    - set +e
    - du -sh $CI_PROJECT_DIR/.gradle/wrapper
    - du -sh $CI_PROJECT_DIR/.gradle/caches
    - set -e
    - ./gradlew assembleDebug
    - mkdir artifacts
    - cp mobile/build/outputs/apk/*.apk artifacts/
    - cp wear/build/outputs/apk/*.apk artifacts/
  cache:
    key: $CI_PROJECT_NAME
    paths:
      - .gradle/wrapper/
      - .gradle/caches/
      - build/
      - mobile/build/
      - wear/build/
  artifacts:
    name: "project_${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}"
    expire_in: 2 weeks
    paths:
      - artifacts/
like image 107
rpadovani Avatar answered May 23 '26 22:05

rpadovani