鍍金池/ 問答/Java  Linux  網(wǎng)絡(luò)安全/ gitlab-ci集成的時候,gitlab-ci.yml怎么配置緩存,不要每次b

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

下面是我.gitlab-ci.yml里面的內(nèi)容:

stages:
  - compile

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

job_compile:
  stage: compile
  script:
    - mvn compile

在Maven的setting.xml文件中,我設(shè)置本地倉庫也是/cache/local/repo/,但是每次編譯時候都會重新下載jar包。
能不能緩存jar包,加快速度。

回答
編輯回答
無標(biāo)題

要配置 key 參數(shù)才能生效,取值可以直接使用gitlab的預(yù)定義變量(Environment Variables),從你的配置文件看是要跨 stage 共享數(shù)據(jù),可以使用變量 CI_BUILD_STAGE:

stages:
  - compile

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

job_compile:
  stage: compile
  script:
    - mvn compile
2018年4月25日 21:14