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-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
- Compute a version from the commit sha.
- Pass it as
--consumer-app-versionand add--branch. - Confirm the variable is non-empty before publishing.
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.
test -n "$GITHUB_SHA" || { echo "sha empty"; exit 1; }How to prevent it
- Always pass a commit-sha consumer version to publish.
- Add
--branchso selectors and can-i-deploy can find the pact. - Validate the version variable is non-empty before publishing.