Connect your Bitbucket Pipeline to Humanitec

Overview

This page 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

pipelines:
  tags:
     '*': 
        - step:
            name: Build Image
            services:
              - docker
            script:
              - docker build -t $BITBUCKET_REPO_SLUG:$BITBUCKET_COMMIT .
              - docker save --output tmp-image.docker $BITBUCKET_REPO_SLUG:$BITBUCKET_COMMIT
            artifacts:
              - 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 Account Settings.
  4. Click on your organization.
  5. Select the Module Sources tab.
  6. 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 an internal module that can be added to your environments.