Environments and deployments
Can-i-deploy answers "is it safe to deploy this version to production?" To answer, Apiome has
to know what runs in production now. You tell it with environments and deployment
records: create each environment once, then have your deploy job record every deployment or
release. The pact-broker CLI does this against Apiome unchanged, and the Environments page
does it in the app.
The Environments pages show what is recorded — which version
runs where, each environment's deployment history — and simulate a deployment before you make it.
What is recorded here is also used by the deployed,
released and environment consumer-version selectors, so a provider verifies
the pacts of the consumer versions that are really in production.
Before you start
- Your pacts are published to Apiome, so the versions you record exist. A deployment can only be recorded for a version Apiome already has.
- Set
PACT_BROKER_BASE_URLto your workspace's broker base URL (https://api.apiome.dev/v1/tenants/<workspace>/pact-broker) andPACT_BROKER_TOKENto an API key. Create the key on API keys for a member with the Editor role: it can create environments and record deployments.
Create your environments
In the app
You need Pacts → Create.
- In the rail, under Ship, click Contracts, then the Environments tab.
- Click New environment.
- In Display name, type the name people read, such as
Production EU. Name fills in as you type (production-eu); change it if your deploy jobs use another. It is one word, with no spaces. - Turn on Production for a production environment. It is marked red everywhere, and verification never sends requests that change data there.
- Turn on Contracts required to make can-i-deploy refuse a version that has no verified contract here.
- Optional: in Contact and Contact email, say who looks after it (
Platform team,platform@acme.dev). - Click Create environment.


/ade/dashboard/pacts/environmentsA field the workspace would refuse says so under it before anything is sent — a name with a space,
or one another environment already has. The same, from anywhere shows the
apiome pact create-environment command for what you filled in; the Pact CLI pill leaves out
--contract-required, which only Apiome has.
To change an environment, click ⋯ on its row in Environments, then Edit environment.
Saving replaces every field. Contacts the dialog does not show (a second contact, say) are kept as
they are, and the dialog says so. Renaming keeps every deployment. No apiome pact command changes
an environment yet, so The same, from anywhere shows the REST request. You need Pacts →
Edit.
To delete one, click ⋯ → Delete environment (Pacts → Delete). While any version is deployed or released there, the dialog says so — “Production still has 9 versions running.” — and offers no delete. Record their undeployment or end their support first.
From a script
Create each environment once, for example from a setup script:
pact-broker create-environment --name test --display-name Test
pact-broker create-environment --name production --display-name Production --production
| Field | What it is |
|---|---|
name | The name your deploy jobs use (production). One word, no spaces, unique in the workspace. |
displayName | The name people read (Production). The name is used when you leave it out. |
production | Whether this is a production environment. Defaults to false. |
contractRequired | Apiome only. When true, can-i-deploy to this environment refuses a version that has no contract. Defaults to false. |
contacts | Who to contact about the environment: [{"name": "Team Ledger", "details": {"emailAddress": "…"}}]. |
pact-broker list-environments lists them with their uuid. Use the uuid with
describe-environment, update-environment and delete-environment. Renaming an environment
keeps its deployments, because they refer to it by uuid. Deleting an environment deletes every
deployment and release recorded to it, and cannot be undone.
Set contractRequired with the API, since the CLI has no flag for it:
curl -X PUT "$PACT_BROKER_BASE_URL/environments/<uuid>" \
-H "Authorization: Bearer $PACT_BROKER_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "production", "displayName": "Production", "production": true, "contractRequired": true}'
A PUT replaces every field, so send the ones you want to keep.
Record a deployment
Add this to your deploy job, after the deployment succeeds:
pact-broker record-deployment \
--pacticipant "Ledger API" \
--version "$GIT_COMMIT" \
--environment production
- The deployment replaces the one before it. The version deployed to that environment before is marked as no longer deployed. It stays in the history, with the time it was replaced.
- Recording the same version again changes nothing. The answer is
200with the existing deployment instead of201. - The version must already be recorded, by publishing a pact or verifying one. Otherwise the
CLI reports
<pacticipant> version <version> not found.
Application instances
Some environments run more than one copy of an application at once: one per region, or one per
customer. Name the copy with --application-instance:
pact-broker record-deployment --pacticipant "Ledger API" --version 4f1e2d0 \
--environment production --application-instance eu-1
A deployment then only replaces the previous deployment to the same instance. Deploying to
eu-1 leaves us-1 running its own version, and both count as deployed. Leave the instance out
when the environment has one copy.
Record an undeployment
When you take an application out of an environment without deploying another version, record it:
pact-broker record-undeployment --pacticipant "Ledger API" --environment production
Add --application-instance eu-1 to take only that copy out. You do not need to record an
undeployment when you deploy a new version: record-deployment does that for you. apiome pact record-undeployment takes the same flags, and the Environments board's column menu has Record an
undeployment (in the app).
Record a release
Use a release instead of a deployment for an application where several versions are in use at once, such as a mobile app or a library: releasing 2.0 does not replace 1.0.
pact-broker record-release --pacticipant "Billing App" --version 2.0.0 --environment app-store
Every released version stays supported until you record that support has ended:
pact-broker record-support-ended --pacticipant "Billing App" --version 1.0.0 --environment app-store
Recording a release of the same version again starts supporting it again. apiome pact record-support-ended takes the same flags; in the app, use End support on the board
(End support for a release).
Record from the app
A deployment or a release that happened outside a pipeline — a hotfix, a manual rollout, an app store release — can be recorded on the Environments page. See Record a deployment in the app and Record a release in the app. The page asks can-i-deploy first, and recording over a “no” needs an explicit tick that is written to the audit trail.
What the provider verifies
A provider's verifier picks up what you recorded with these selectors (see Choose pacts to verify with selectors):
| Selector | What it selects |
|---|---|
{"deployed": true, "environment": "production"} | Every consumer version currently deployed to production, on every instance. |
{"released": true} | Every consumer version released and still supported, in any environment. |
{"deployedOrReleased": true} | Both of the above. |
{"environment": "production"} | Every consumer version deployed or supported in production. |
The reasons in the verifier's output name the environment: deployed to production.
Read what is recorded
| To read | Request |
|---|---|
| Every environment | GET …/pact-broker/environments (?name=production for one) |
| What is deployed to an environment now | GET …/environments/<uuid>/deployed-versions/currently-deployed?pacticipant=Ledger%20API |
| What is supported in an environment now | GET …/environments/<uuid>/released-versions/currently-supported |
| Every deployment of one version to an environment, current or not | GET …/pacticipants/ledger-api/versions/4f1e2d0/deployed-versions/environment/<uuid> |
| One deployment or release | GET …/deployed-versions/<uuid>, GET …/released-versions/<uuid> |
A version's document (GET …/pacticipants/ledger-api/versions/4f1e2d0) lists one
pb:record-deployment and one pb:record-release link per environment, each named after its
environment. This is how the CLI finds where to post.
When a request is refused
| Status | Code | What to do |
|---|---|---|
404 | pacticipant-version-not-found | The version is not recorded yet. Publish its pacts or record it first. |
404 | pact-environment-not-found | No environment with that uuid in this workspace. List them with list-environments. |
409 | pact-environment-name-taken | Another environment already has the name. |
422 | pact-environment-invalid | The environment is malformed. pointer names the field: /name with a space in it, /production not true or false. |
422 | pact-deployment-invalid | currentlyDeployed or currentlySupported was set to true. Record the deployment or release again instead. |
401 / 403 | — | The token is not a valid API key for this workspace, or its member lacks the Pacts permission below. |
Who can do what
| Action | Needs | Viewer | Editor | Admin | Owner |
|---|---|---|---|---|---|
| List environments and read deployments | pacts:view | ✓ | ✓ | ✓ | ✓ |
| Create an environment, record a deployment or a release | pacts:create | — | ✓ | ✓ | ✓ |
| Change an environment, record an undeployment or the end of support | pacts:edit | — | ✓ | ✓ | ✓ |
| Delete an environment | pacts:delete | — | — | ✓ | ✓ |
Related
- Pact Broker concepts — pacticipants, versions, environments and deployments.
- Choose pacts to verify with selectors — the environment selectors.
- Can I deploy? — gate a deployment on what is recorded here.
- Environments and the deploy simulator — see what is recorded and simulate a deployment.
- Publish verification results — what can-i-deploy reads with this.
- Pact Broker API — every endpoint, parameter and error code.