Integrate Context within your Bitbucket CI/CD flow

Bitbucket pipelines build

Add a new Context annotation after each success deploy

Bitbucket Pipelines is an integrated CI/CD service, built into Bitbucket. It allows you to automatically build, test and even deploy your code, based on a configuration file in your repository.

The Pipelines configuration file (bitbucket-pipelines.yml) defines all your build configurations and you can easily add a new step to automatically annotate on Context each successful deploy.

If you have not yet configured your Bitbucket pipeline, we recommend you take a look at this article where they explain how it works.

Bitbucket pipelines build

Add the Context step

Add the following step on your bitbucket-pipelines.yml file:

   ...
     default:
       - step:
           name: Add Context annotation
           script:
             - description=$(git log -1 --pretty=format:%s)
             - curl -H "Content-Type:application/json" -X POST --url XXXXX_CONTEXT_URL_XXXXX --data '{"title":"'"${BITBUCKET_REPO_OWNER}"' release version '"${BITBUCKET_BUILD_NUMBER}"'","category":"Release '"${BITBUCKET_REPO_SLUG}"'","description":"'"$description"'","url":"'"${BITBUCKET_GIT_HTTP_ORIGIN}"'/addon/pipelines/home#!/results/'"${BITBUCKET_BUILD_NUMBER}"'"}'
  

Configuration options & default variables

Pipelines provides a set of default variables that are available for builds, and can be used in your Context annotation request.

Default variable Description
CI Default value is true. Gets set whenever a pipeline runs.
BITBUCKET_BUILD_NUMBER The unique identifier for a build. It increments with each build and can be used to create unique artifact names.
BITBUCKET_CLONE_DIR

The absolute path of the directory that the repository is cloned into within the Docker container.

BITBUCKET_COMMIT

The commit hash of a commit that kicked off the build.
BITBUCKET_REPO_OWNER The name of the account in which the repository lives.
BITBUCKET_REPO_OWNER_UUID The UUID of the account in which the repository lives.
BITBUCKET_REPO_SLUG The URL-friendly version of a repository name.
BITBUCKET_REPO_UUID The UUID of the repository.
BITBUCKET_BRANCH

The source branch. This value is only available on branches.

Not available for builds against tags, or custom pipelines.

BITBUCKET_TAG

The tag of a commit that kicked off the build. This value is only available on tags.

Not available for builds against branches.

BITBUCKET_BOOKMARK For use with Mercurial projects.
BITBUCKET_PARALLEL_STEP

Zero-based index of the current step in the group, for example: 0, 1, 2, …

Not available outside a parallel step.

BITBUCKET_PARALLEL_STEP_COUNT

Total number of steps in the group, for example: 5.

Not available outside a parallel step.

BITBUCKET_PR_ID The pull request ID.
BITBUCKET_PR_DESTINATION_BRANCH

The pull request destination branch (used in combination with BITBUCKET_BRANCH).

Only available on a pull request triggered build.

BITBUCKET_GIT_HTTP_ORIGIN The URL for the origin.
BITBUCKET_GIT_SSH_ORIGIN Your SSH origin, for example: git@bitbucket.org:/<account>/<repo>.git

BITBUCKET_EXIT_CODE

The exit code of a step, can be used in after-script sections. Values can be 0 (success) or 1 (failed)