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
      - yarn.lock
  policy: pull
    - 'node_modules/'

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

The output in the console is:

Restoring cache
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.


1 Like

I created a simple test project on 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)?

I have the same problem. 653KiB yarn.lock and the cache key changes every time I push.

The problem seems to be that it also takes the commit into account (!?) so if you force push a commit that doesn’t change the yarn.lock file (but the commit has a yarn.lock file) then it gets a new sha. Very confusing.

Hi, did anyone find a solution to this? It’s definitely related to force pushing a commit with no change to watched file.