Pnpm cache not extract correctly in jobs

Problem to solve

I have three jobs in the same stage, and one pre install job before this stage.

the pre install job upload pnpm install caches with lock file as the cache key.

and in next jobs, the three job can’t extract cache correctly. As i see, randomly they can extract the correct .pnpm-store directory and match the cache, randomly they can’t.

I dont know why, the three jobs running at same commit and same runner, but they dont perform the same.

you can see the difference in the screenshot below, they both echo Successfully extracted cache, but only one list the .pnpm-store directory.

I wish all the jobs could extract the .pnpm-store directory successfully and then i can use it.

Steps to reproduce

Configuration

image: node:18.12.0-alpine

stages:
  - pre
  - test

.node_modules-cache: &node_modules-cache
  key:
    files:
      - pnpm-lock.yaml
  paths:
    - .pnpm-store
  policy: pull

.pnpm:
  tags:
    - fe
  before_script:
    - ls -al
    - corepack enable
    - corepack prepare pnpm@latest-8 --activate
    - pnpm config set store-dir .pnpm-store

install:
  extends: .pnpm
  stage: pre
  script:
    - pnpm install --frozen-lockfile --prefer-offline
  cache:
    - <<: *node_modules-cache
      policy: push

lint:
  extends: .pnpm
  stage: test
  script:
    - pnpm install --frozen-lockfile --ignore-scripts --prefer-offline
    - pnpm lint
  cache:
    - <<: *node_modules-cache

typecheck:
  extends: .pnpm
  stage: test
  script:
    - pnpm install --frozen-lockfile --ignore-scripts --prefer-offline
    - pnpm typecheck
  cache:
    - <<: *node_modules-cache

build:
  extends: .pnpm
  stage: test
  script:
    - pnpm install --frozen-lockfile --ignore-scripts --prefer-offline
    - NODE_ENV=production pnpm build
  cache:
    - <<: *node_modules-cache

Versions

Please select whether options apply, and add the version information.

  • Self-managed
  • GitLab.com SaaS
  • Self-hosted Runners

Versions

  • GitLab (Web: /help or self-managed system information): 15.11.2
  • GitLab Runner, if self-hosted (Web /admin/runners or CLI gitlab-runner --version): 16.3.1