How to Deploy Through Test, Staging, and Production Environments in Bitbucket Pipelines
Tag each deploy step with deployment: test, deployment: staging, or deployment: production so each tier uses its own environment-scoped variables and shows in the deploy dashboard.
Bitbucket has three built-in deployment environment tiers: Test, Staging, and Production. Setting deployment: on a step binds it to that environment, gives it the environment variables you defined there, and tracks the release on the Deployments tab.
Steps
- In Repository settings to Deployments, add variables per environment.
- Set
deployment: test/staging/productionon each step. - Order the steps so promotion flows test to staging to production.
- Read the same variable name in each step; the value differs per environment.
Pipeline
bitbucket-pipelines.yml
pipelines:
branches:
main:
- step:
name: Deploy to test
deployment: test
script:
- ./deploy.sh --url $DEPLOY_URL
- step:
name: Deploy to staging
deployment: staging
script:
- ./deploy.sh --url $DEPLOY_URL
- step:
name: Deploy to production
deployment: production
trigger: manual
script:
- ./deploy.sh --url $DEPLOY_URLGotchas
- Each environment name (test/staging/production) can be used once per pipeline ordering by default.
- Production deploys must happen after staging in the same branch unless you relax ordering rules.
- Variables defined on an environment override repository variables of the same name.
Related guides
How to Deploy With a Manual Trigger Step in Bitbucket PipelinesMake a deploy step wait for a human click in Bitbucket Pipelines with trigger: manual, so the build runs auto…
How to Use a Secured Deployment Variable in Bitbucket PipelinesPass secrets to a Bitbucket Pipelines deploy with secured deployment variables, which are masked in logs and…