Skip to content
Latchkey

How to Use Deployment Environments in Bitbucket Pipelines

The deployment keyword on a step links it to an environment so Bitbucket tracks release history.

Tag a deploy step with deployment: production. Bitbucket records it in the Deployments view and injects environment-scoped variables.

Tag a step with an environment

The deployment keyword links the step to the production environment.

bitbucket-pipelines.yml
pipelines:
  branches:
    main:
      - step:
          name: Deploy
          deployment: production
          script:
            - ./deploy.sh --token "${DEPLOY_TOKEN}"

Notes

  • Define environments (test, staging, production) in Repository settings > Deployments.
  • Variables scoped to an environment override repository variables when that environment runs.
  • Configure deployment permissions and gates on the environment to control who can promote.

Related guides

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