gitlab ci总是下载依赖项-运行程序中的缓存不起作用

时间:2020-08-14 13:35:44

标签: maven gitlab-ci gitlab-ci-runner

我是gitlab CI的新手,正在尝试使用gitlab构建我的maven项目。 我创建了自己的Docker镜像进行构建,并且正在使用本地运行程序。
我的.gitlab-ci.yml如下所示:已编辑:

image: registry.gitlab.com/girishenoy2003/docker-java-8-mvn-3.6.3:latest
services:
  - docker:dind
stages:
  - compile
  - test
before_script:
  - export MVN_USER_HOME=`pwd`/.m2
cache:
  paths:
    - $MVN_USER_HOME/.m2/repository/
    - target/
maven-compile:
  stage: compile
  script:
    - mvn compile
  tags:
    - my-local-runner
  only:
    - master
maven-test:
  stage: test
  script:
    - mvn test
  tags:
    - my-local-runner
  only:
    - master

在编译阶段,我希望所有依赖项都可以下载并缓存它,并且在运行测试时,我希望它可以从缓存中获取它,因为我将我的本地运行程序用于这两个作业。

如何避免从依赖的jar文件中下载不同的作业?

PS:

  • 我已经看过这个question-但没有帮助
  • 我知道,如果我使用mvn test-compile可以达到目的,但我想在不同的工作中做到这一点

编辑: 一些跑步日志:

Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/aws-learning-path/spring-boot-rest/.git/
Checking out f86f9c63 as master...
Removing "..\\..\\..\\cache\\aws-learning-path\\spring-boot-rest\\default\\cache.zip"
Removing target/
Skipping Git submodules setup
Restoring cache
00:00
Checking cache for default...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
$ export MVN_USER_HOME=/root
$ mvn test
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.2.RELEASE/spring-boot-starter-parent-2.2.2.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.2.RELEASE/spring-boot-starter-parent-2.2.2.RELEASE.pom (8.1 kB at 3.3 kB/s)

1 个答案:

答案 0 :(得分:0)

您的问题与您的/ root文件夹有关

gitlab-runner不会在项目目录之外缓存任何路径,您需要配置CI以下载并将依赖项存储在项目路径中