Skip to content
Latchkey

How to Model Environments in the Pact Broker

Environments are first-class objects the broker uses to track which version is deployed where, powering accurate can-i-deploy checks.

Register each environment once with create-environment. Then record-deployment and can-i-deploy reference it by name to reason about live versions.

Steps

  • Run create-environment for each real environment, once.
  • Mark production with --production for stricter semantics.
  • Use the environment name in can-i-deploy and record-deployment.

Create an environment

Terminal
npx pact-broker create-environment \
  --name production \
  --production \
  --broker-base-url "$PACT_BROKER_BASE_URL" \
  --broker-token "$PACT_BROKER_TOKEN"

Gotchas

  • Environments replaced the older per-environment tags; do not mix the two models.
  • can-i-deploy with --to-environment requires the environment to exist first.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →