Cache key file creates a new hash on every build

I am having the problem that on every new pipeline my cache for the node_modules misses and is recreated.

Even though I have set the key to the yarn.lock file Gitlab CI creates a new cache key for every commit.

Here is my config:

cache: &yarn_cache
  key:
    files:
      - yarn.lock
  policy: pull
  paths:
    - 'node_modules/'

install dependencies:
  stage: install
  interruptible: false
  cache:
    <<: *yarn_cache
    policy: pull-push
  script:
    - time yarn install --frozen-lockfile --no-progress --non-interactive

The output in the console is:

Restoring cache
00:01
Checking cache for ea648fb349a089e115e8f732eef012e018d72e46...
FATAL: file does not exist                         
Failed to extract cache

This happens on every push. When I restart the job using the UI the key stays the same. Also for all the following jobs the cache key is the same and works.
However, the key should be the same for all commits that use that yarn.lock file.

Regards
Simon

1 Like

I created a simple test project on gitlab.com here: Simon Bächler / Gitlab-CI Cache Test · GitLab

But there I cannot reproduce the behaviour. The cache key is stable across all pipelines.

Could it be because our yarn.lock is quite big (590kb)?