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-environmentfor each real environment, once. - Mark production with
--productionfor 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-environmentrequires the environment to exist first.
Related guides
How to Gate a Deploy With can-i-deployRun pact-broker can-i-deploy in CI before shipping so the broker confirms the version you are about to deploy…
How to Record Deployments and Releases in the Pact BrokerTell the Pact Broker which version is live in each environment using record-deployment and record-release, so…