Skip to content
Latchkey

How to Use Deployment Environments in Bitbucket Pipelines

The deployment: key tags a step with an environment so Bitbucket tracks what shipped where on the Deployments dashboard.

Mark a deploy step with deployment: staging or deployment: production. Bitbucket records the deployment and can scope environment-specific variables to it.

A tracked production deploy

Tagging the step with deployment: production surfaces it on the Deployments view.

bitbucket-pipelines.yml
pipelines:
  branches:
    main:
      - step:
          name: Deploy to production
          deployment: production
          script:
            - ./deploy.sh production

Gotchas

  • Bitbucket has three built-in environment tiers (test, staging, production); names must map to these.
  • Deployment variables defined on an environment are injected only into steps tagged with that environment.
  • You can require admin approval on an environment to gate production deploys.

Related guides

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