π Bitbucket Deployment Approval Process Setup Guide
This document outlines the setup for deployment approvals in Bitbucket Pipelines using deployment environments with access controls, instead of manual triggers in the pipeline YAML.
π Why Use Deployment Environments?
Bitbucketβs deployment
feature allows you to:
- Control who can deploy to staging or production
- Require pull request approval before deployment
- Maintain an audit log of deployments
- Reduce the risk of unauthorized production pushes
This is far more secure and auditable compared to trigger: manual
.
βοΈ Step 1 β Define Environments in bitbucket-pipelines.yml
Update your pipeline to use deployment:
instead of trigger: manual
.
pipelines:
branches:
staging:
- step:
name: Build and Prepare
script:
- echo "Building app..."
- go build -o app
artifacts:
- app
- step:
name: Deploy to Staging
deployment: staging # Link to "staging" environment
runs-on:
- self.hosted
- linux.shell
- nsestaging
script:
- echo "Deploying to STAGING..."
- cp app /path/to/application/code
tags:
v*:
- step:
name: Build for Production
script:
- go build -o app
artifacts:
- app
- step:
name: Deploy to Production
deployment: production # Link to "production" environment
runs-on:
- self.hosted
- linux.shell
- nseprod
script:
- echo "Deploying to PRODUCTION..."
- cp app /path/to/application/code
βοΈ Step 2 β Configure Deployment Environments in Bitbucket
-
Navigate to Repository Settings β Deployments
-
Add new environments:
staging
production
-
Each environment will now be available in Pipelines.
π Step 3 β Set Deployment Permissions
For each environment:
-
Go to Repository Settings β Deployments β [Environment] β Permissions
-
Define which groups or users can deploy:
- Staging: Allow DevOps + Senior Developers
- Production: Allow only Release Managers or Ops
-
Optionally, enable:
- β Require pull request approval before deployment
- β
Restrict deployments from specific branches (e.g., only
main
)
π Example Approval Flow
- A developer merges a feature branch into
main
. - The pipeline builds the artifact.
- For
staging
, only approved users can run the deploy step. - For
production
, a tag (v1.0.0
) must be created, and only authorized approvers can deploy.
π Benefits
- Audit trail β Who deployed, what commit, when.
- Access control β Only specific users can trigger staging/production releases.
- Reduced risk β No accidental deploys by unauthorized users.
- Governance β Enforced approval workflows aligned with DevOps best practices.
β With this setup, deployments are secure, auditable, and approval-gated by role, not just by repository access.