Bitbucket repositoty status badges!

In the picture: Nice looking badges at the top of a Bitbucket repository (by the author)

Part 1: Just using this solution

Getting the files

  1. Download the bitbucket-pipelines.yml and files found in this Github gist and add them to your repository:
  2. Create a ci folder at the root of your repository and move the file there. The bitbucket-pipelines.yml should stay at the root of the repository

Dependecy installation

Coverage report

Setup the required Pipelines variables

Updating your README file to show the badges

|Build-Status| |Coverage|.. |Build-Status| image::
.. |Coverage| image::
# my-project[![Build-Status](](!/)

Part 2: Understanding how it works

The required files

  1. bitbucket-pipelines.yml — This is the configuration file for Bitbucket’s CI/CD component, much like Github Actions or independent ones like Travis or Circle CI. Most of the logic goes here.
  2. — A script generating the appropriate status and coverage badges. I placed this in a directory named ci in the root of my repository.
  3. README.rst (or ) — Here you just reference the right urls for the generated badges.
  4. pytest.ini or arguments you provide to the pytest command — Not really a part of the solution, but the script assumes your testing phase generates a coverage report.

The overall structure

- <<: *test
- <<: *test
- <<: *upload-status-badge
- <<: *upload-coverage-badge
- <<: *build-status
  1. Run the test phase, which will run all tests AND generate appropriate status.svg and coverage.svg files AND will save them (and the exit code returned by the pytest command) using the Bitbucket Pipelines artifacts mechanism.
  2. Upload the status badge to the Downloads section of your repository.
  3. Upload the coverage badge to the Downloads section of your repository.
  4. Run a step that will simply exit with the previously-stored exit value returned by pytest. This will make sure the build will fail if pytest fails, but will pass if everything goes fine.
  • The easiest way, at the moment, to upload Bitbucket Pipelines build artifacts to the corresponding repository’s Downloads store/section is using the official bitbucket-upload-file docker/step (see here for details).
  • Bitbucket Pipelines does not, at the moment, support running pipeline steps after a step has failed. As a result, and since upload is done by separate steps, we can’t have the test step — and thus the pytest command — fail, and so we have to add a final step just to make the overall build status correspond to test results. Not very elegant, but it’s the best I could think of.

Dependencies & assumptions

  • pytest runs the tests.
  • coverage and pytest-cov produce coverage reports on pytest runs
  • pybadges generates the build status badge.
  • coverage-badge generates the coverage badge.


Data Science consultant.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

IT Service Management: How Businesses Benefit From the ITIL Standards

Flutter TODO APP With GetX

Containers and Kubernetes

Overview of the RedPrairie Standard Solution

Create Azure DevOps Resources with Terraform using the new Azure DevOps Provider

Zero to App — Single Codebase (Android, iOS, and Web) — Flutter Development Story

21 Quick Two-liner Tips for Junior Developers

Google Workspace Alerts fears turn into a Flutter Web MVP

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shay Palachy

Shay Palachy

Data Science consultant.

More from Medium

Design Pattern- The Observer Pattern

Yet another Postgres migration: updating primary key type to bigint

Using scratch as a base for a Docker Container

Golang, One Language for AI, Web, and Cloud Development