liveBook · Manning

Pact Broker CLI

As explained in Contract Testing in Action

A command-line interface for publishing and managing Pact contracts and interacting with a Pact Broker.

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

How Contract Testing in Action covers it

How deep it goes
Demonstrates publishing, environment creation, and webhook creation, while deferring improved contract versioning.
Examples
Uses versioned Pact files, a local Dockerized broker, a staging environment, and a GitHub-dispatch verification webhook.
What it assumes
Assumes generated Pact files, an installed Pact library or CLI image, and broker connection credentials where authentication is enabled.
What you can do after
Apply it via Pact Broker CLI to publish contracts and configure environments or verification-triggered webhooks.
How it connects
Connects Pact Broker, PactFlow, consumer-driven contract testing, CI/CD pipelines, webhooks, environments, and deployments.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Contract Testing in Action. The section links point to the parts of the book it draws on.