我正在尝试在 .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