Skip to content
Latchkey

Pact "pact-broker publish: consumer version required" in CI

The publish command needs a version to file the pact under. Without --consumer-app-version, the CLI exits before contacting the broker. The version should be the commit sha so it is unique and traceable.

What this error means

The publish step fails immediately with "consumer version required" or "--consumer-app-version ... is required" and never uploads a pact.

Pact
pact-broker publish ./pacts --broker-base-url https://acme.pactflow.io
Error: The consumer app version is required. Please specify --consumer-app-version.

Common causes

No consumer version was passed

The publish command omitted --consumer-app-version, so the broker has no version to associate the pact with.

The version variable was empty in CI

A shell variable meant to hold the sha resolved to empty, so the flag was present but blank.

How to fix it

Publish with the git sha and branch

  1. Compute a version from the commit sha.
  2. Pass it as --consumer-app-version and add --branch.
  3. Confirm the variable is non-empty before publishing.
Terminal
pact-broker publish ./pacts \
  --consumer-app-version "$(git rev-parse --short HEAD)" \
  --branch "$(git rev-parse --abbrev-ref HEAD)" \
  --broker-base-url "$PACT_BROKER_BASE_URL"

Fail early if the sha is empty

Guard the publish so a missing sha stops the job with a clear message instead of a blank version.

Terminal
test -n "$GITHUB_SHA" || { echo "sha empty"; exit 1; }

How to prevent it

  • Always pass a commit-sha consumer version to publish.
  • Add --branch so selectors and can-i-deploy can find the pact.
  • Validate the version variable is non-empty before publishing.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →