Integrate your build system with Bitbucket Cloud

 

It is possible that your build system or vendor already integrates with Bitbucket Cloud. When already integrated, you can see the build status on each commit that triggers a build.

When you don't see a build status, you can integrate your builds on your own, as long as your build tool is able to run scripts. To integrate, add a script after the last step of your build that update your commits on Bitbucket.

The Python script below provides an example of what to add as your last build step. This script includes the following fields that either the tool updates based on environment variables or that you can enter manually in the script:

 

Field

Updated...

Description

key

by build

The key that distinguishes the build status from other statuses associated with the same commit. The script uses the example of BUILD_ID.

state

by build or manually in script

An indication of the status of the commit. Because the script runs after the build, the status will be either SUCCESSFUL or FAILED.

Depending on your build system, you can either use environment variables to provide the state, or you can create two separate scripts (with the state already included) that run depending on the outcome of the build.

name

by build

The name of the build. The script uses the example of JOB_NAME.

url

by build

The URL to the page with details of the build. The script uses the example of BUILD_URL.

description

by build or manually in script

A description of the build. Depending on your build system, you can either use an environment variable to provide the description or add a description to the script before it runs. The script uses the example of The build passed.

owner

manually in script

The account of the repository owner. The script uses the example of emmap1.

For more information about the api_url, see the statuses/build Resource.

repo_slug

manually in script

The repository name. The script uses the example of MyRepo.

For more information about the api_url, see the statuses/build Resource.

revision

by build

The SHA1 value for the commit with the build status. The script uses the example of GIT_COMMIT.

For more information about the api_url, see the statuses/build Resource.

auth

manually in script

Your authentication information. You can enter your username and password. However, if your repository is part of a workspace, you can still enter your username and password, or you can enter your workspace name and API key. The script users the example of auth_user and auth_password.

Example script for the end of your build

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #!/usr/bin/env python import os import requests # Use environment variables that your CI server provides to the key, name, # and url parameters, as well as commit hash. (The values below are used by # Jenkins.) data = { 'key': os.getenv('BUILD_ID'), 'state': 'SUCCESSFUL', # or 'FAILED' for a script that runs when the build fails 'name': os.getenv('JOB_NAME'), 'url': os.getenv('BUILD_URL'), 'description': 'The build passed.' } # Construct the URL with the API endpoint where the commit status should be # posted (provide the appropriate owner and slug for your repo). api_url = ('https://api.bitbucket.org/2.0/repositories/' '%(owner)s/%(repo_slug)s/commit/%(revision)s/statuses/build' % {'owner': 'emmap1', 'repo_slug': 'MyRepo', 'revision': os.getenv('GIT_COMMIT')}) # Post the status to Bitbucket. (Include valid credentials here for basic auth. # You could also use team name and API key.) requests.post(api_url, auth=('auth_user', 'auth_password'), json=data)

Still need help?

The Atlassian Community is here for you.