Bitbucket Pipelines

Notify Bugsnag of builds using Bitbucket Pipelines.

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

Set up Pipeline

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

    #!/bin/bash -e
    # Usage: [release-stage]
    # release-stage           The release stage (Optional, defaults to “production”).
    # Environment variable:
    # BUGSNAG_API_KEY         The API key associated with the project, required.
    # BUGSNAG_AUTO_ASSIGN     Auto assign all new errors in this release-stage to this build (Optional, defaults to “false“)
    # BUGSNAG_APP_VERSION     The version of the app being built (Optional, defaults to “BITBUCKET_BUILD_NUMBER“)
    if [ -z "$RELEASE_STAGE" ]; then
    if [ -z "$BUGSNAG_API_KEY" ]; then
      echo "Bugsnag API key must be set"
      exit 1
    if [ "$BUGSNAG_AUTO_ASSIGN" = true ]; then
    if [ -z "$BUGSNAG_APP_VERSION" ]; then
    curl \
      -X POST \
      -H "Content-Type: application/json" \
      -d "{\"apiKey\":\"${BUGSNAG_API_KEY}\",\"appVersion\":\"${APP_VERSION}\",\"releaseStage\":\"${RELEASE_STAGE}\",\"autoAssignRelease\":${AUTO_ASSIGN_RELEASE},\"buildTool\":\"bitbucket-pipelines\",\"sourceControl\":{\"repository\":\"${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}\",\"revision\":\"${BITBUCKET_COMMIT}\"}}"

    If you are using Bugsnag On-premise, you should use your Bugsnag Build API endpoint rather than

  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 in your build, passing the release stage as an argument to the script. For example, to notify Bugsnag of a production build every time a commit is made to master add the following:

          - step:
               - ./ production
  4. Configure the BUGSNAG_APP_VERSION depending on how the appVersion is set in your application:

    • If appVersion is configured within your notifier you should export this value to the BUGSNAG_APP_VERSION environment variable to be picked up by the script. BUGSNAG_AUTO_ASSIGN should not be set.
    • If not, you should set BUGSNAG_AUTO_ASSIGN to true. BUGSNAG_APP_VERSION can optionally be set, and will default to the automatically incrementing BITBUCKET_BUILD_NUMBER.

Configuration options

You can set the following environmental variables to override or specify additional deploy information:

Variable Description
BUGSNAG_API_KEY Your Bugsnag API key (required)
BUGSNAG_APP_VERSION The building applications version (optional, defaults to BITBUCKET_BUILD_NUMBER)
BUGSNAG_AUTO_ASSIGN Whether new errors in this release stage should be automatically assigned to this build. This should only be set to true if you are unable to configure the appVersion in your notifier (optional, defaults to false)