GitLab CI中的Maven项目构建不会为后续构建使用缓存

时间:2018-06-17 17:19:37

标签: maven continuous-integration gitlab

我有一个Maven项目,以测试GitLab的CI功能。这是我的配置(我已经检查了几个示例,tried几乎每个组合/设置都是这样的:

image: openjdk:8u171-jdk-slim-stretch

stages:
  - test

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

cache:
  paths:
    - .m2/repository/

before_script:
  - ./mvnw --version

test:
  stage: test
  script:
    - ./mvnw verify

我了解工件将是缓存 d并且不需要在使用此配置的成功构建之间反复下载,实际上我在触发构建时会看到这些日志:

section_start:1529253663:restore_cache
Checking cache for default...
Downloading cache.zip from http://runners-cache-4-internal.gitlab.com:444/runner/project/7034854/default
Successfully extracted cache
section_end:1529253664:restore_cache
...
section_end:1529253698:build_script
section_start:1529253698:after_script
section_end:1529253699:after_script
section_start:1529253699:archive_cache
Creating cache default...
.m2/repository/: found 1551 matching files
target/: found 40 matching files
Uploading cache.zip to http://runners-cache-4-internal.gitlab.com:444/runner/project/7034854/default
Created cache
section_end:1529253702:archive_cache
section_start:1529253702:upload_artifacts
section_end:1529253703:upload_artifacts
Job succeeded

...但我也看到每次从Maven Central下载每个工件/ jar文件。

任何了解GitLab CI的人都可以解释一下吗?

这是完整的日志:https://gist.github.com/x80486/96e1e7274d179073d7deef26048a6d34

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,在缓存中添加了一个密钥为我修复了它:

image: maven:latest
cache:
  key: "maven3"
paths:
  - .m2/repository/