How to Track Deployments With Environments in Bitbucket Pipelines
The deployment key tags a step with an environment (test, staging, production) so Bitbucket tracks it and applies that environment's variables.
Add deployment: <environment> to a step. The environment must be one of test, staging, or production (or a custom one defined in repo settings).
Steps
- Define the environment under Repository settings to Deployments if it is custom.
- Add
deployment: productionto the deploying step. - The Deployments view then records each release to that environment.
bitbucket-pipelines.yml
bitbucket-pipelines.yml
pipelines:
branches:
main:
- step:
name: Deploy to production
deployment: production
script:
- ./deploy.sh --env prodGotchas
- Bitbucket enforces ordering: a step cannot deploy to production before staging if both exist in the pipeline.
- Deployment variables defined on the environment only resolve inside steps that name that environment.
Related guides
How to Use Secured Variables in Bitbucket PipelinesUse repository, deployment, and workspace variables in Bitbucket Pipelines, marking secrets as secured so the…
How to Add a Manual Step in Bitbucket PipelinesPause a Bitbucket Pipelines run for human sign-off by adding trigger: manual to a step, so a deploy waits for…