# Bitbucket Pipelines

Run Bitbucket Pipelines steps on Groundbox: a fresh VM for each step, billed per second at the same prices as GitHub Actions jobs. Steps on self-hosted runners use none of Bitbucket's build minutes. You add a `runs-on` to a step in `bitbucket-pipelines.yml`. Bitbucket Cloud only.

## Connect a workspace

Groundbox needs a credential that reads repositories and pipelines and manages runners. Either:

- **An OAuth consumer** (any plan). In Bitbucket, open the workspace's **Settings > OAuth consumers > Add consumer**, tick **This is a private consumer**, give it any callback URL, and the permissions **Repositories: Read**, **Pipelines: Read** and **Runners: Write**. Copy its key and secret.
- **An access token**: a workspace access token, or a repository access token for one repository, with the scopes `repository`, `pipeline` and `runner:write`.

Then, in the dashboard, open **Repos and runners > Bitbucket > Connect a workspace**. Or, with an API key that has `ci:write`:

```
export BITBUCKET_CONSUMER_KEY=... BITBUCKET_CONSUMER_SECRET=...   # or BITBUCKET_ACCESS_TOKEN=...
groundbox ci bitbucket connect acme             # --repo web for a repository token
```

The API has it at `POST /v1/ci/bitbucket/connections`, and the SDKs as `connect_bitbucket`. Groundbox checks the credential with Bitbucket and keeps it encrypted; it is never shown again. `groundbox ci bitbucket` (`GET /v1/ci/bitbucket`, `get_bitbucket`) lists the connections, and `groundbox ci bitbucket disconnect <id>` stops taking a workspace's steps.

## Use it

```
pipelines:
  default:
    - step:
        name: Test
        image: node:22        # as on Bitbucket: the step runs in this container
        runs-on:
          - self.hosted
          - linux
          - groundbox.4vcpu   # or groundbox for the auto size
        script:
          - npm ci
          - npm test
```

A step whose `runs-on` has `self.hosted` and one Groundbox size runs on Groundbox: `groundbox.2vcpu`, `groundbox.4vcpu`, `groundbox.8vcpu`, `groundbox.16vcpu`, or `groundbox` for the auto size, which picks a size per step from its earlier runs. Other steps stay on Bitbucket's own runners.

Bitbucket takes only letters, digits and dots in `runs-on` labels, so the sizes are written with a dot (`groundbox.4vcpu`), not the hyphen used on GitHub and GitLab. A label with a hyphen fails the whole pipeline before any step starts.

In a new workspace, Bitbucket turns Pipelines on only for someone with two-step verification on in their Bitbucket settings (**Personal settings > Two-step verification**). Without it the **Enable Pipelines** switch stays grey.

## How a step runs

Groundbox watches the connected workspace's running pipelines. When a step with a Groundbox label is ready, it registers a self-hosted runner with that step's labels in the workspace (or the repository, for a repository token), starts a fresh VM, and runs Bitbucket's Linux Docker runner on it. The runner takes the step, and once the step is done the VM stops and the runner is deleted. A step's `image:` and `services:` run in containers on its own VM, as on Bitbucket. The step's log, artifacts, status and stop button are Bitbucket's own. The dashboard lists each step with its time and cost and links to it.

Groundbox finds a step's `runs-on` by reading `bitbucket-pipelines.yml` at the pipeline's commit and matching the step by its `name`, so give steps that run on Groundbox a name. A new step is usually picked up within about 15 seconds.

## Checkup

`groundbox ci bitbucket checkup acme/web` (`GET /v1/ci/checkup/bitbucket?repo=acme/web`, `bitbucket_checkup`, or the Checkup card on the Bitbucket tab) reads the last month of a repository's pipelines and shows the build minutes by step size (a 2x step costs two build minutes a minute), what they cost as extra minutes ($10 per 1,000), the slowest steps and their queue time, and what the same steps cost on Groundbox. It needs `ci:read`.

## Limits

- Bitbucket Cloud only, Linux steps only.
- Bitbucket limits how many self-hosted runners a workspace can have and, with premium runners, how many run at once; Groundbox's runners count toward that.
- Live logs, the terminal on a job and test insights are for GitHub Actions jobs only for now.
- Pipeline `caches:` do not carry over between steps: each step starts on a clean VM.
