Pact Broker CLI is a command-line interface for sending Pact contract artifacts to a Pact Broker or PactFlow and for administering broker-backed delivery workflows. It makes contract publication and selected broker configuration repeatable from a terminal or CI pipeline, rather than relying only on the web UI. section 9.6 section 9.3.3
A typical first use is publishing the Pact files generated by consumer contract tests. Configure the broker base URL and token as environment variables, then run `pact-broker publish ./pacts` with a consumer application version and broker credentials. A successful publish creates a broker-visible contract; it remains unverified until the provider verifies it. section 4.4
Use the CLI to automate broker interactions that belong in delivery workflows:
- Publish contracts from a `pacts` directory, associating them with a consumer application version and optional tag. section 4.4
- Create broker environments such as `staging` so recorded environments reflect the deployment pipeline. section 10.2.3
- Create a webhook that reacts when a contract requiring verification is published, for example by dispatching a GitHub workflow request. section 10.4.1
- Run the publishing command under a CI system account, while reserving broader permissions for administrators and limiting most users to viewing or debugging contracts. section 9.3.3
Publish to a local Dockerized broker
When Pact Broker runs locally in Docker, run the Pact CLI Docker image with the project directory mounted, set `PACT_BROKER_BASE_URL=http://localhost:92`, and invoke `publish` on the local `pacts` directory with an application version. The command prints the URLs of the published pacts when it succeeds. This provides the broker’s core contract-sharing workflow without requiring a hosted service. section 9.4.1
Listing 9.5 Pact CLI publish contracts
docker run --rm \
--network=host \ #1
-w ${PWD} \
-v ${PWD}:${PWD} \
-e PACT_BROKER_BASE_URL=http://localhost:92 \
pactfoundation/pact-cli:latest \
publish \
${PWD}/pacts \
--consumer-app-version 0.0.0
The Docker command shows the practical boundary between the local workspace, the CLI container, the broker URL, and the versioned Pact artifacts being published. section 9.4.1
Treat credentials as deployment configuration rather than command text. Hosted PactFlow uses a base URL and API token; CI should use a dedicated system account. The CLI supports both hosted and self-hosted brokers, while the broker itself is responsible for sharing contracts, tracking change relationships, and helping coordinate releases. section 4.4 section 9.3.3 section 9.6
