我为Circle CI创建了配置:
version: 2
jobs:
dependencies:
docker:
- image: circleci/node:10
steps:
- checkout
- restore_cache:
keys:
- v2-dependencies-{{ checksum "package.json" }}
- v2-dependencies-
- run: yarn install
- save_cache:
paths:
- node_modules
- /root/.cache/Cypress
key: v2-dependencies-{{ checksum "package.json" }}
test:
docker:
- image: cypress/base:10
steps:
- checkout
- restore_cache:
keys:
- v2-dependencies-{{ checksum "package.json" }}
- v2-dependencies-
- run: ls -la
- run: yarn cy:cache
- run: yarn cy:ci
- run: yarn report:coverage
workflows:
version: 2
build:
jobs:
- dependencies
- test:
requires:
- dependencies
我期望的是: 它应该首先安装所有依赖项并将其缓存以在以后的工作中使用这些依赖项(例如用于测试)
会发生什么: 它会安装所有依赖项并对其进行缓存,但是在 test 作业中,它将取消存档缓存,但不在测试运行所在的目录中。
ls -la 的输出:
我做错了。如何正确使用上一个作业的缓存?
答案 0 :(得分:1)
您应该使用相同映像来使用缓存,因为每个映像都使用不同的目录。在此示例中,您尝试从错误的目录获取缓存。
version: 2
jobs:
dependencies:
docker:
- image: cypress/base:10
steps:
- checkout
- restore_cache:
keys:
- dependencies-{{ checksum "yarn.lock" }}
- dependencies-
- run: yarn install
- save_cache:
paths:
- node_modules
- /root/.cache/Cypress
key: dependencies-{{ checksum "yarn.lock" }}
test:
docker:
- image: cypress/base:10
steps:
- checkout
- restore_cache:
keys:
- dependencies-{{ checksum "yarn.lock" }}
- dependencies-
- run: yarn cy:cache
- run: yarn cy:ci
- run: yarn report:coverage
workflows:
version: 2
build:
jobs:
- dependencies
- test:
requires:
- dependencies