【发布时间】:2016-02-29 15:39:26
【问题描述】:
我正在尝试在 .gitlab-ci.yml (http://doc.gitlab.com/ce/ci/yaml/README.html#cache) 中使用“缓存”。我的 gitlab 版本是 8.2.1,我的 Runner 是:
$ docker exec -it gitlab-runner gitlab-runner -v
gitlab-runner version 0.7.2 (998cf5d)
所以根据文档,一切都是最新的,但我无法使用缓存;-(。我所有的文件总是被删除。我做错了什么吗?
创建了一个缓存存档,但没有传递给下一个作业。
这是我的 .gitlab-ci.yml
$ cat .gitlab-ci.yml
stages:
- createcache
- testcache
createcache:
type: createcache
cache:
untracked: true
paths:
- doc/
script:
- touch doc/cache.txt
testcache:
type: testcache
cache:
untracked: true
paths:
- doc/
script:
- find .
- ls doc/cache.txt
作业“createcache”的输出
Running on runner-141d90d4-project-2-concurrent-0 via 849d416b5994...
Fetching changes...
HEAD is now at 2ffbadb MUST BE REVERTED
[...]
$ touch doc/cache.txt
[...]
Archiving cache...
INFO[0000] Creating archive cache.tgz ...
INFO[0000] Done!
Build succeeded.
作业“testcache”的输出
Running on runner-141d90d4-project-2-concurrent-0 via 849d416b5994...
Fetching changes...
Removing doc/cache.txt
[...]
$ ls doc/cache.txt
ls: cannot access doc/cache.txt: No such file or directory
ERROR: Build failed with: exit code 1
我的解决方法
我的解决方法是手动解压缩 /cache 目录中的内容...我很确定这不是使用缓存的正确方法...
$ cat .gitlab-ci.yml
stages:
- build
- test
- deploy
image: ubuntu:latest
before_script:
- export CACHE_FILE=`echo ${CI_PROJECT_DIR}/createcache/${CI_BUILD_REF_NAME}/cache.tgz | sed -e "s|/builds|/cache|"`
createcache:
type: build
cache:
untracked: true
paths:
- doc/
script:
- find . | grep -v ".git"
- mkdir -p doc
- touch doc/cache.txt
testcache:
type: test
script:
- env
- find . | grep -v ".git"
- tar xvzf ${CACHE_FILE}
- ls doc/cache.txt
【问题讨论】:
-
这可能是由于您的减少方式,但请注意“不要将缓存与阶段之间的传递工件混为一谈。缓存并非旨在在阶段之间传递工件。” docs.gitlab.com/ee//ci/caching/index.html#cache-vs-artifacts
标签: gitlab gitlab-ci gitlab-ci-runner