Gitlab-CI-Runner does silently fail to retrieve cache, if cache:key is invalid
Summary
When following the Job configuration documentation and adding a cache-key from it, the cache will fail silently. This seems to be true for any key that does not meet the requirements (especially about not containing a "/").
The documentation explicitly states to use $CI_COMMIT_REF_NAME
- but that name can contain illegal characters, when the branch name is e.g. feature/some-new-thing
.
Proposed solution
Fix the executor to not silently ignore invalid keys, but warn about them
Note: Since the .gitlab-ci.yml-validator cannot really predict, which variable will resolve to which values when it's checking the validity, I think the above solution is better than adding some sanity checks to the .gitlab-ci.yml-validator
Steps to reproduce
- This was tested for gitlab-multi-runner 10.4 with kubernetes executor
- open a new branch with a compound key like "feature/12345"
- Add the following cache-key to any
.gitlab-ci.yml
cache:
key: "$CI_COMMIT_REF_NAME"
Actual behavior
The executor log does not show any sign of a cache setting or a problem hinting on an invalid key. It will simply ignore the cache completely, as if the entry would not exist.
Expected behavior
The executor should ignore the cache, but put out a warning. This would help a developer greatly in debugging the issue.
Relevant logs and/or screenshots
## the log of a correct run (cache-key is valid)
Running on gitlab/runner-abcdefg-project-123-concurrent-123456 via gitlab-runner-123456-987654...
Cloning repository for feature/gitlab-cache with git depth set to 1...
Cloning into '/group/project'...
Checking out b1348594 as feature/gitlab-cache...
Skipping Git submodules setup
Checking cache for feature/gitlab-cache...
Downloading cache.zip from http://minio-service:9000/runner/runner/abcdefg/project/123/feature/gitlab-cache
Successfully extracted cache
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Login Succeeded
[...snip...]
Creating cache feature/gitlab-cache...
node_modules/: found 26281 matching files
Uploading cache.zip to http://minio-service:9000/runner/runner/abcdefg/project/123/feature/gitlab-cache
Created cache
## the *actual* log of a run (invalid cache key - current incorrect behavior)
Running on gitlab/runner-abcdefg-project-123-concurrent-123456 via gitlab-runner-123456-987654...
Cloning repository for feature/gitlab-cache with git depth set to 1...
Cloning into '/group/project'...
Checking out b1348594 as feature/gitlab-cache...
Skipping Git submodules setup
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Login Succeeded
[...snip...]
Job succeeded
## the *expected* log of a run (invalid cache key - proposed correct behavior)
Running on gitlab/runner-abcdefg-project-123-concurrent-123456 via gitlab-runner-123456-987654...
Cloning repository for feature/gitlab-cache with git depth set to 1...
Cloning into '/group/project'...
Checking out b1348594 as feature/gitlab-cache...
Checking cache for feature/gitlab-cache...
WARNING: Invalid cache key found, ignoring cache.
Skipping Git submodules setup
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Login Succeeded
[...snip...]
Job succeeded
Environment description
- Custom gitlab installation 10.4.3
- gitlab-runner 10.4.0
- gitlab-executor kubernetes
- Kubernetes 1.8.6