Skip to content

CML with Bitbucket Cloud

Casper da Costa-Luis edited this page Jun 16, 2021 · 2 revisions

CML now works with Bitbucket Cloud! Here, we'll show you how.

In Bitbucket Cloud, you can use the Bitbucket Pipelines CI/CD system to run workflows automatically on triggering events. When your workflow includes a CML report, you'll see it appear as a comment on the corresponding commit- like the report below:

The key file in any Bitbucket Pipeline project is bitbucket-pipelines.yml. For example, to generate the report pictured above, your bitbucket-pipelines.yml file should look like this:

image: dvcorg/cml-py3:latest

pipelines:
  default:
      - step:
          name: Train model
          script: 
            - pip install -r requirements.txt
            - python train.py
      
            # Print metrics
            - cat metrics.txt > report.md
            - echo >> report.md 
            
            # Add image
            - cml-publish confusion_matrix.png --md >> report.md
            
            # Send comment
            - cml-send-comment report.md

To see this CML report in context, check out our project repo.

Repository variables

You'll need to create a variable called repo_token so CML can authenticate with the Bitbucket Cloud API. Because the API requires a username and password, you have two options:

  1. Use the access credentials from a user on your team (note that you may also consider using Bitbucket Cloud App Passwords to generate a password just for CML, if you would prefer).
  2. Create a designated "CI/CD" account to author CML reports.

Whichever you choose, the steps to create your repo_token will be the same:

  1. Use a Base64 encoder of your choice to encode your username and password: printf $USERNAME:$PASSWORD | base64. Copy the resulting token.
  2. In your repository, go to Repository Settings -> Repository Variables.
  3. In the field "Name", enter repo_token.
  4. In the field "Value", enter your Base64 transformed string.
  5. Check Secured to ensure that your credentials are hidden in all Bitbucket Pipelines logs.

Self-hosted runners

At this time, Bitbucket Pipelines do not support self-hosted runners. Please see their official docs to learn more about pricing options if you have significant computing needs.

Sample repository

Check out our sample CML project repository in Bitbucket Cloud.

Clone this wiki locally