Cache fallback doesn't take increment index into account
## Summary Quote from @qventura https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/1534#note_435187741: > I've been struggling to have a useful usage of this feature, and just figured out this was because of this: https://docs.gitlab.com/ee/ci/caching/#clearing-the-cache-manually > Basically, every time the cache get cleared, an integer get appended to the cache key. So my `CACHE_FALLBACK_KEY` which is `master` never match with the actual `master` cache which is `master-xxx` ## Steps to reproduce <!-- What do you need to do to reproduce the bug? Please include job definitions or git repository structure if relevant --> 1. Clear cache manually https://docs.gitlab.com/ee/ci/caching/#clearing-the-cache-manually 1. Run pipeline for the `main` branch. After it, you will have a cache for the `main` branch. 2. Make some branch from the `main` 2. Run pipeline for it <!-- Please add the definition of the job from `.gitlab-ci.yml` that is failing inside of the code blocks (```) below. --> <details> <summary> .gitlab-ci.yml </summary> ```yml jest: stage: quality_check variables: CACHE_FALLBACK_KEY: jest-main cache: key: jest-$CI_COMMIT_REF_SLUG paths: - .jestcache/ when: 'always' script: - yarn jest ``` </details> ## Actual behavior The fallback will not have a cache index and will not use fallback: ``` Restoring cache Checking cache for feature/ci-shared-cache-9... FATAL: file does not exist Failed to extract cache Checking cache for main... FATAL: file does not exist ``` <!-- What actually happens --> ## Expected behavior It should fall back on `$CACHE_FALLBACK_KEY-$CACHE_INCREMENT_INDEX` (I did not find the real variable name in sources) <!-- What you should see instead --> ## Relevant logs and/or screenshots <!-- Paste the job logs inside of the code blocks (```) below so it would be easier to read. --> <details> <summary> job log </summary> ```sh Restoring cache Checking cache for feature/ci-shared-cache-9... FATAL: file does not exist Failed to extract cache Checking cache for main... FATAL: file does not exist ``` </details> ## Environment description Custom installation, but I think it doesn't matter. <!-- Are you using shared Runners on GitLab.com? Or is it a custom installation? Which executors are used? Please also provide the versions of related tools like `docker info` if you are using the Docker executor. --> <!-- Please add the contents of `config.toml` inside of the code blocks (```) below, remember to remove any secret tokens! --> ### Used GitLab Runner version ``` Version: 13.6.0 Git revision: 8fa89735 Git branch: 13-6-stable GO version: go1.13.8 Built: 2020-11-21T06:16:31+0000 OS/Arch: linux/amd64 ``` <!-- Please run and paste the output of `gitlab-runner --version`. If you are using a Runner where you don't have access to, please paste at least the first lines the from build log, like: --> ## Possible fixes As I understand we should append an incrementing index to `CACHE_FALLBACK_KEY` <!-- (If you can, link to the line of code that might be responsible for the problem) ---> @erik.lindahl @tmaczukin
issue