Visitar URL original
ReserveCacheError: Unable to reserve cache with key <cache-key> · Issue #722 · gradle/actions · GitHub
Skip to content

ReserveCacheError: Unable to reserve cache with key <cache-key> #722

Open

Description

@bennettp123

When using a reusable build inside a matrix workflow, only one of the jobs is able to write its cache.

example:

# .github/workflows/main.yaml

on:
  push: [main]

jobs:
  build-android:
    strategy:
      matrix:
        app-name:
          - app1
          - app2
    uses: ./.github/workflows/reusable-build.yaml
    with:
      app-name: ${{ matrix.app-name }}
# .github/workflows/reusable-build.yaml

on:
  workflow_call:
    inputs:
      app-name:
        required: true
        type: string
jobs:
  build:
    steps:
      
      # ...
      
      - uses: gradle/actions/setup-gradle@v4
      
      # ... build <app-name>

In the example above, one of the gradle steps will successfully write its cache, but the other fails with error

Failed to save cache entry with path '<path>' and key: <key>: ReserveCacheError: Unable to reserve cache with key <key>, another job may be creating this cache.

Both jobs have the same key. Edit: the cache key doesn't include anything for the matrix context (eg gradle-home-v1|Linux-X64|build[ef6094c74d56794d327380021ca7a151]-2baefdce1c4b89355ff1a945a35e960b6289568f)

Activity

  1. bennettp123 commented on Sep 4, 2025

    @bennettp123
    Author

    Assuming this is caused by colliding cache keys. Looking at the cache-key.ts, it already attempts to include the matrix context in the cache key.

    I'm guessing it's because the matrix context is only defined at the top level, and it doesn't propagate into the reusable workflow.

    Possible workarounds:

    • move the matrix from main.yaml to reusable-build.yaml, so it's defined inside the workflow
    • add a dummy matrix to reusable-build.yaml
      # .github/workflows/reusable-build.yaml
      jobs:
        build:
          strategy:
            matrix:
              app-name: [${{ inputs.app-name }}]
          steps:
            # ...
            - uses: gradle/actions/setup-gradle@v4
              env:
                GRADLE_BUILD_ACTION_CACHE_KEY_JOB_INSTANCE: ${{ inputs.app-name }}
    • explicitly set workflow-job-context
      # .github/workflows/reusable-build.yaml
      jobs:
        build:
          steps:
            # ...
            - uses: gradle/actions/setup-gradle@v4
              with:
                workflow-job-context: { app-name: ${{ inputs.app-name }} }
    • override GRADLE_BUILD_ACTION_CACHE_KEY_JOB_INSTANCE
      # .github/workflows/reusable-build.yaml
      jobs:
        build:
          steps:
            # ...
            - uses: gradle/actions/setup-gradle@v4
              env:
                GRADLE_BUILD_ACTION_CACHE_KEY_JOB_INSTANCE: ${{ inputs.app-name }}
  2. bigdaz commented on Sep 4, 2025

    @bigdaz
    Member

    This is an issue specific to reusable workflows, and is discussed extensively in this issue: #316 (comment)

    Unfortunately, we haven't been able to find a way to differentiate between different instances of the same reusable workflow: these jobs share the same name, matrix and everything else that goes into the cache key.

    Setting workflow-job-context is likely the best workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions