简体   繁体   English

Gradle的GitLab Runner缓存无效

[英]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. 我使用GitLab Runner作为CI来构建Android项目,但缓存不起作用。

Here's my .gitlab-ci.yml . 这是我的.gitlab-ci.yml It was modified from https://gist.github.com/daicham/5ac8461b8b49385244aa0977638c3420 . 它是从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. 我也尝试使用gradle参数设置gradle用户home,积极指定.gradle/ for cache等,但它们都没有工作。

Any ideas? 有任何想法吗?

If you use Gitlab < 9.0,you add to specify the cache has to be shared among different pipelines. 如果您使用Gitlab <9.0,则添加以指定必须在不同管道之间共享缓存。

Try to add key: $CI_PROJECT_NAME under cache : 尝试在cache下添加key: $CI_PROJECT_NAME

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/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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