GitLab CI缓存密钥

GitLab CI缓存密钥,gitlab,gitlab-ci,gitlab-ci-runner,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 no

假设我在
.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
它不尝试检索任何缓存,只尝试运行脚本(显然失败)。根据法律,这是正确的方法。(我正在使用docker runner)

以下是我得到的输出:

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

我正在使用标记来确保相同的运行程序正在执行作业。

请尝试将密钥更新到以下位置:

cache:
  key: ${CI_COMMIT_REF_SLUG}

这解决了我的问题。我有三个阶段——构建、测试、打包。没有设置为${CI\u COMMIT\u REF\u SLUG}的键,缓存只在测试阶段工作。更新密钥后,现在package stage也可以正确提取缓存。

缓存用于在下载依赖项(例如npm或composer)时加快构建过程。您不应该使用缓存将创建的文件从一个阶段移交到另一个阶段,而应该使用工件。见: