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
- Compute a version from the commit sha.
- Pass it as
--consumer-app-versionand add--branch. - 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
--branchso selectors and can-i-deploy can find the pact. - Validate the version variable is non-empty before publishing.
Related guides
Pact "Error publishing pact ... 409 Conflict" in CIFix Pact "Error publishing pact: 409 Conflict" in CI - the broker rejected a republish of the same consumer v…
Pact "can-i-deploy ... no records found" in CIFix Pact "can-i-deploy ... there is no matrix ... no records found" in CI - the broker has no matrix rows for…
Pact consumerVersionSelectors returns no pacts in CIFix Pact consumerVersionSelectors returning no pacts in CI - the selectors point at a branch, tag, or environ…