Bitbucket Pipelines

Notify Bugsnag of deploys using Bitbucket Pipelines.

By sending the source revision when you deploy a new version of your app using Bitbucket Pipelines, you’ll be able to see which deploy each error was introduced in and link back to the code in the repo.

Set up Pipeline

  1. Create the following script called bugsnag-deploy.sh in your repo and make sure it has execute permissions.

    #!/bin/bash -e
    
    # Usage: bugsnag-deploy.sh [release-stage]
    # release-stage           The release stage (Optional, defaults to “production”).
    # Environment variable:
    # BUGSNAG_API_KEY         The API key associated with the project.
    
    RELEASE_STAGE=$1
    if [ -z "$RELEASE_STAGE" ]; then
      RELEASE_STAGE="production"
    fi
    
    if [ -z $BUGSNAG_API_KEY ]; then
      echo "Bugsnag API key must be set"
      exit 1
    fi
    
    curl https://notify.bugsnag.com/deploy \
      -X POST \
      -d "apiKey=${BUGSNAG_API_KEY}&releaseStage=${RELEASE_STAGE}&repository=https://bitbucket.org/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}&revision=${BITBUCKET_COMMIT}&branch=\"${BITBUCKET_BRANCH}\""
    
  2. Define the following environment variable in Bitbucket Repository Settings -> Pipelines -> Environment variables.

    • BUGSNAG_API_KEY - The API key for your Bugsnag project
  3. In bitbucket-pipelines.yml execute the script after a deployment in your build, passing the release stage as an argument to the script. For example, to notify Bugsnag of a deploy to production every time a commit is made to master add the following:

    pipelines:
      branches:
        master:
          - step:
             script:
               - ./bugsnag-deploy.sh production