Skip to content

GitLab CI

  1. Add GOCOV_TOKEN under Settings → CI/CD → Variables on the group or project, holding your workspace's upload token. Mark it masked, but not protected — GitLab checks "Protect variable" by default, and protected variables never reach merge request pipelines. (Or add nothing and upload without a token.)

  2. Include the gocov component and hand it the coverage file your test job leaves as an artifact:

include:
  - component: gitlab.com/gocov/gocov/upload@1
    inputs:
      files: coverage.out
      needs: [test]

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

test:
  image: golang:1.27
  script:
    - go test ./... -covermode=atomic -coverprofile=coverage.out
  artifacts:
    paths: [coverage.out]

Only the test command and files change for other languages — Languages & formats lists what each test tool writes.

The component adds one job, gocov-upload, after the jobs named in needs. It downloads the pinned gocov CLI release for the runner's architecture, verifies its sha256 against the release's checksums.txt, and uploads every file matching files (comma-separated, globs allowed) — no toolchain to install. Several files become one report, so they share a format — see Several files. Project path, commit, branch and MR iid are auto-detected, including the real head SHA on merged-results pipelines. The workflow rules run the pipeline on merge requests and the default branch without duplicates. Every input is listed under Options.

Note that gitlab.com's free tier requires a verified account (credit card) before shared runners pick up jobs.

Uploading without a token

GitLab can mint a short-lived, signed OIDC ID token for a job, so you can drop the GOCOV_TOKEN variable entirely. The component's job already declares the id_tokens entry it needs, with your gocov server as its aud: leave the variable out and the upload goes via OIDC — the uploader reads the token from GOCOV_ID_TOKEN and the server verifies which project it came from.

The project's workspace (its GitLab group) must already be registered on gocov and connected to GitLab — the same connection that posts the commit status and merge-request note. The project itself needs no setup: its first OIDC upload registers it, exactly as a token upload would. OIDC replaces only the upload token; publishing still goes through that connection. A pasted GOCOV_TOKEN always takes precedence, so existing setups are untouched, and a rejected OIDC upload logs the reason and exits 0 rather than failing the build, except under fail-on-gate.

Without the component, declare the entry yourself — it must be named GOCOV_ID_TOKEN, and the aud must equal your gocov server's URL (https://app.gocov.dev on the hosted service, your instance's URL when self-hosting):

coverage:
  image: golang:1.27
  id_tokens:
    GOCOV_ID_TOKEN:
      aud: 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

On a self-managed GitLab, the OIDC tokens are issued under your instance's own URL; the gocov operator has to trust that issuer before its uploads are accepted — see self-hosting.

Options

input meaning
files coverage file(s) to upload — comma-separated, globs allowed
needs required: the job(s) whose artifacts hold the coverage files; the upload runs after them
stage the stage the upload job runs in
job-name the upload job's name. Include the component once per part, each with its own name and part
server only when self-hosting: your instance's URL. On the hosted service the server is implicit
part names one slice of a build split across jobs — see Parts
ignore glob patterns for files to leave out, comma-separated, on top of the repo's own — see Ignoring files
fail-on-gate true fails the job, with exit status 3, when the commit fails its coverage gate — see Blocking merges on coverage
allow-failure true lets the pipeline pass when the upload job fails, over the upload or over the gate
version the gocov CLI release to download; the default is the one that component release was tested against
image the image the upload job runs in

The component's README gives each input's default, and is where the CI/CD Catalog lists it. @1 follows the newest 1.x release; @1.0.0 pins one.

Without the component

A self-managed GitLab cannot include components from gitlab.com's catalog. Either mirror the component project into your instance and include it from there, or download the CLI in the job yourself — the checksum line pins the binary:

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

coverage:
  image: golang:1.27
  script:
    - go test ./... -covermode=atomic -coverprofile=coverage.out
    - curl -fsSLO https://github.com/gocov/gocov/releases/download/v0.42.0/gocov-linux-amd64
    - curl -fsSL https://github.com/gocov/gocov/releases/download/v0.42.0/checksums.txt
      | grep ' gocov-linux-amd64$' | sha256sum -c -
    - chmod +x gocov-linux-amd64
    - ./gocov-linux-amd64 upload coverage.out

Blocking merges on coverage

With the workspace connected, every upload sets a commit status and posts a diff-coverage note on the merge request. To make the coverage gate block merges, reference the gocov commit status under Settings → Merge requests → Status checks.

The upload job can also fail on the gate itself, connected or not: with fail-on-gate: true a commit that fails its gate fails the job with exit status 3, where an upload that does not land exits 1 — a refused OIDC upload included, since its gate went unchecked. To let the pipeline pass over an upload that did not land and still stop on the gate, allow only exit code 1 on the job, under the name it has in your pipeline:

include:
  - component: gitlab.com/gocov/gocov/upload@1
    inputs:
      files: coverage.out
      needs: [test]
      fail-on-gate: true

gocov-upload:
  allow_failure:
    exit_codes: 1