Deploy with pull requests

Managing deployments with pull requests and Bitbucket Pipelines is simple, you just need to adopt a certain structure for your repository.



On this page



Step 1: Define the repository structure

Repository branches:


master Your integration branch
staging Use this branch to trigger deployments to staging
production Use this branch to trigger deployments to production
features/xxx All feature branches


With the branch structure above, you can define a .YML file that has different flows for different branches:

# This is a sample build configuration for Javascript.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:4.6.0

    - step:
          - npm install
          - npm test
      - step:
            - npm install
            - npm test
            - export HEROKU_APP_NAME=$STAGING_APP
            - ./ # Check to understand how to deploy to Heroku
      - step:
            - npm install
            - npm test
            - export HEROKU_APP_NAME=$PROD_APP
            - ./  # Check to understand how to deploy to Heroku


  • All branches except staging and production will use the default pipeline that simply runs the test
  • The staging and the deployment branch have a different configuration and are set up to deploy to their respective staging and production environments

Step 2: Set branch permissions

In order to protect the staging and production branches from being pushed to directly, you can use the branch permissions to only allow merges via pull requests.

In the example balow, branch permissions are set in a way that everyone can merge to staging, but only selected individuals can merge to production:


Step 3: Start deploying with pull requests

You can now simply develop a new feature or improvements on the feature branches and integrate them into the master. Then, you can issue a pull request to the staging branch to deploy changes to your staging environment:


Creating a pull request allows you to review the changes you deploy them to the staging environment. Repeat the process to deploy to production: create a pull request going from the staging branch to the master branch.

The image below presents a view of a pull request merged from staging to production:





Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport