我有一个 gitlab 作业,它下载一堆依赖项并将它们填充到缓存中(如果需要),然后我有一堆使用该缓存的作业。我注意到在消耗作业结束时,他们花费了大量时间创建新的缓存,即使他们没有对其进行任何更改。
是否可以让他们只充当消费者?只读?
cache:
paths:
- assets/
configure:
stage: .pre
script:
- conda env update --prefix ./assets/env/base -f ./environment.yml;
- source activate ./assets/env/base
- bash ./download.sh
parse1:
stage: build
script:
- source activate ./assets/env/base;
- ./build.sh -b test -s 2
artifacts:
paths:
- build
parse2:
stage: build
script:
- source activate ./assets/env/base;
- ./build.sh -b test -s 2
artifacts:
paths:
- build
最佳答案
深深地埋在非常详细的.gitlab-ci.yml
中文档是对名为 policy
的 cache
设置的引用。 。 GitLab 缓存具有push
(又名write
)和pull
(又名read
)的概念。默认情况下,它设置为pull-push
(在开头读取
,在结尾写入
)。
If you know the job does not alter the cached files, you can skip the upload step by setting
policy: pull
in the job specification. Typically, this would be twinned with an ordinary cache job at an earlier stage to ensure the cache is updated from time to time:
这几乎描述了这种情况:作业configure
更新缓存,而parse
作业不改变缓存。
在消费作业中,添加:
cache:
paths:
- assets/
policy: pull
为了清楚起见,在全局设置中明确这一点可能不会有什么坏处:
cache:
paths:
- assets/
policy: pull-push
关于continuous-integration - 有没有办法让 GitLab 缓存在不被写入的情况下被使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62366523/