GitLab CI缓存密钥

时间:2019-04-04 09:33:34

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

假设我在.gitlab-ci.yml文件中执行以下步骤:

setup_vue:
 image: ....
 stage: setup
 script:
   - cd vue/
   - npm install --no-audit
 cache:
   key: node-cache
   paths: 
     - vue/node-modules/

我明白了

Checking cache for node-cache-1...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache

在脚本运行后:

Creating cache node-cache-1...
Created cache
WARNING: vue/node-modules/: no matching files 
No URL provided, cache will be not uploaded to shared cache server. Cache will be stored only locally. 
Job succeeded

当我尝试在下一步中获取缓存时,如下所示:

test_vue:
 image: ....
 stage: test
 cache:
   key: node-cache
 script:
   - cd docker-hotreload-vue
   - cqc src
   - npm test

它不尝试检索任何缓存,而只是尝试运行脚本(显然失败)。根据{{​​3}},这是执行此操作的正确方法。 (我正在使用dockerRunner)

这是我得到的输出:

Fetching changes...
fatal: remote origin already exists.
Removing vue/node_modules/
HEAD is now at ....
Checking out ...

Skipping Git submodules setup
$ cd docker-hotreload-vue
$ cqc src

我正在使用标签来确保同一跑步者正在执行作业。

1 个答案:

答案 0 :(得分:0)

尝试将密钥更新为以下内容:

cache:
  key: ${CI_COMMIT_REF_SLUG}

这解决了我的问题。我经历了3个阶段-构建,测试和打包。如果没有将密钥设置为$ {CI_COMMIT_REF_SLUG},则缓存仅适用于测试阶段。更新密钥后,现在打包阶段还可以正确提取缓存。

相关问题