Skip to content

Bitbucket Pipelines

Add the gocov pipe after your tests and name your gocov server under the step's oidc.audiences; the upload needs no secret at all:

- step:
    oidc:
      audiences:
        - https://app.gocov.dev   # your gocov server URL
    script:
      - go test ./... -covermode=atomic -coverprofile=coverage.out
      - pipe: docker://gocov/upload-pipe:0
        variables:
          FILES: coverage.out

The one prerequisite: the repository's Bitbucket workspace is registered on gocov and connected to Bitbucket. The repository itself needs no setup — its first upload registers it.

Commit, branch, repo and PR id are auto-detected. When self-hosting, use your instance's URL as the audience and add SERVER: with the same URL to the pipe's variables. Only the test command and the FILES: path change for other languages — Languages & formats lists what each test tool writes. Several files in FILES become one report, so they share a format — see Several files.

Uploading without a token

The oidc.audiences entry has Bitbucket hand the step a short-lived, signed OIDC identity token, and binds that token to your server so it can't be replayed elsewhere. The uploader picks the token up from the step's environment and the server verifies which repository it came from.

The audience must equal your gocov server's URL (https://app.gocov.dev on the hosted service, your instance's URL when self-hosting). Bitbucket appends it to the default workspace audience, so the token can carry your server alongside any other resource servers the pipeline already targets.

The workspace connection it relies on also posts the build status and Code Insights report: OIDC replaces only the upload token, and publishing still goes through that connection. A rejected OIDC upload logs the reason and exits 0 rather than failing the build, except under FAIL_ON_GATE.

Using an upload token instead

Add GOCOV_TOKEN as a secured workspace variable holding your workspace's upload token (when self-hosting, add GOCOV_SERVER beside it and pass SERVER: $GOCOV_SERVER to the pipe), leave out the oidc block, and pass the token to the pipe:

- step:
    script:
      - go test ./... -covermode=atomic -coverprofile=coverage.out
      - pipe: docker://gocov/upload-pipe:0
        variables:
          FILES: coverage.out
          TOKEN: $GOCOV_TOKEN

A pasted GOCOV_TOKEN always takes precedence over OIDC, so existing setups are untouched.

Options

variable meaning
FILES required: coverage file(s) to upload — comma-separated, globs allowed
TOKEN the workspace upload token; leave it out when the step uploads via OIDC
PART names one slice of a build split across parallel steps — see Parts
IGNORE glob patterns for files to leave out, comma-separated — see Ignoring files
SERVER only when self-hosting: your instance's URL. On the hosted service the server is implicit
FAIL_ON_ERROR true (the default) fails the step when an upload fails; false only logs a warning
FAIL_ON_GATE true fails the step, with exit status 3, when the commit fails its coverage gate, whatever FAIL_ON_ERROR says — see Blocking merges on coverage
DEBUG true prints every command the pipe runs; false by default

Without Docker

On runners without Docker (the pipe needs it), run the CLI directly instead:

- step:
    oidc:
      audiences:
        - https://app.gocov.dev   # your gocov server URL
    script:
      - go test ./... -covermode=atomic -coverprofile=coverage.out
      - go run github.com/gocov/gocov/cmd/gocov@latest upload coverage.out

With a GOCOV_TOKEN variable instead, leave out the oidc block.

This needs a Go toolchain on the runner; otherwise download the prebuilt binary like any other CI does.

Blocking merges on coverage

With the workspace connected, every upload sets a build status on the commit and attaches a Code Insights report to the PR. To make the coverage gate block merges, require the gocov build in the repo's merge checks — a FAILED status then blocks the PR.

The pipe can also fail its step on the gate itself, connected or not: with FAIL_ON_GATE a commit that fails its gate fails the step. Pair it with FAIL_ON_ERROR: "false" and an upload that does not land only warns, while the gate still stops the step.

Under FAIL_ON_GATE a refused OIDC upload counts as an upload that failed, since its gate went unchecked; FAIL_ON_ERROR decides whether it fails the step or warns.

- pipe: docker://gocov/upload-pipe:0
  variables:
    FILES: coverage.out
    FAIL_ON_ERROR: "false"
    FAIL_ON_GATE: "true"