Connect your Bitbucket Pipeline to Humanitec


This how to guide explains how to push the Docker images for your Bitbucket repositories to Humanitec using Bitbucket Pipelines.

Set up pipelines for the repository

For each repository whose image you want to push to Humanitec, you must have Bitbucket Pipelines enabled.

If you don’t have Pipelines set up, then follow the instructions in the Atlassian documentation.

Note that your Bitbucket Pipelines file must include a step that produces a Docker image. You can use this example:

image: atlassian/default-image:2

        - step:
            name: Build Image
              - docker
              - docker build -t $BITBUCKET_REPO_SLUG:$BITBUCKET_COMMIT .
              - docker save --output tmp-image.docker $BITBUCKET_REPO_SLUG:$BITBUCKET_COMMIT
              - tmp-image.docker 

Next, you will add the components that will allow you to push the image to Humanitec.

Add Humanitec snippet and token

  1. Log in to Humanitec.
  2. Click the profile icon in the top right.
  3. Select Organization Settings.
  4. Select the Images tab.
  5. Click the Bitbucket Pipelines button.

From there, Humanitec will provide you with an access token for connecting to Humanitec’s registry and a code snippet to add to your workflow configuration to push the image. Instructions will appear in the modal.

First, add the token as a repository variable:

  1. Go to the repository you want to connect.
  2. Go to Settings, and then go to Pipelines > Repository variables.
  3. Create a variable called HUMANITEC_TOKEN, and paste the token from the modal as the value.

Then, add the snippet from the modal to the end of your bitbucket-pipelines.yml file and commit the changes.

The last step is to tag the commit. This will trigger a build of your image. If the build is successful, then your image will become available on Humanitec as a module that can be added to your environments.