gitlab-ci集成的时候,gitlab-ci.yml怎么配置缓存,不要每次build都去下载jar包?

下面是我.gitlab-ci.yml里面的内容:

stages:
  - compile

cache:
  paths:
    - /cache/local/repo/

job_compile:
  stage: compile
  script:
    - mvn compile

在Maven的setting.xml文件中,我设置本地仓库也是/cache/local/repo/,但是每次编译时候都会重新下载jar包。
能不能缓存jar包,加快速度。

阅读 13.7k
2 个回答
新手上路,请多包涵

要配置 key 参数才能生效,取值可以直接使用gitlab的预定义变量(Environment Variables),从你的配置文件看是要跨 stage 共享数据,可以使用变量 CI_BUILD_STAGE:

stages:
  - compile

cache:
  key: ${CI_BUILD_STAGE}
  paths:
    - /cache/local/repo/

job_compile:
  stage: compile
  script:
    - mvn compile
cache:
  key: maven-repository-cache
  paths:
    - .m2
variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2"
test:
  image: maven:3.6.0-jdk-8-alpine
  stage: test
  script:
    - mvn test
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题