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

问题描述 投票:0回答:2

我是 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包?

附注:

  • 我已经看过这个问题 - 但没有帮助
  • 我知道如果我使用
    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)
maven gitlab-ci gitlab-ci-runner
2个回答
0
投票

我有一个类似的问题,在我的例子中,变量的值仅在

script
块中可见,而不是在
cache
中。我把它移到了
variables
块。


-1
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.