branchd Docs

Run a job for several versions (matrix)

Run one job once for each combination of values, such as Go versions and databases.

Updated 2026-12-04matrix.mdEdit this page

Available in repositories branchd reads pipeline files for. It is switching repositories on one at a time: until yours is, it keeps running its .forge-ci.yaml or .xeonr-ci.yaml. See What is available.

.branchd/pipelines/ci.yaml
# .branchd/pipelines/ci.yaml
# Test on two Go versions and two databases: four jobs. The include entry
# adds race: true to the cell it agrees with, (1.26, mysql:8).
name: CI
on: [push, pull_request]
jobs:
  test:
    matrix:
      go: ['1.25', '1.26']
      db: ['mysql:8', 'mariadb:11']
      include:
        - {go: '1.26', db: 'mysql:8', race: true}
    image: golang:${{ matrix.go }}
    services:
      db:
        image: ${{ matrix.db }}
        env: {MYSQL_ROOT_PASSWORD: test, MARIADB_ROOT_PASSWORD: test}
    env:
      RACE: ${{ matrix.race }}
    steps:
      - run: go test ${RACE:+-race} ./...
  report:
    # Waits for every cell of test.
    needs: [test]
    image: alpine:3
    steps:
      - run: echo "all cells passed"
  • Cells. matrix: maps keys to lists. The job runs once for each combination: here test (1.25, mysql:8), test (1.25, mariadb:11), test (1.26, mysql:8) and test (1.26, mariadb:11). Each is a check of its own, such as CI / test (1.26, mysql:8).
  • ${{ matrix.<key> }} reads a cell's value, in image:, services:, env:, run: and if:. Each cell's if: is decided on its own.
  • include entries join every cell whose values they agree with, adding their other keys: race: true lands on the (1.26, mysql:8) cell. An entry that agrees with no cell is a cell of its own. In other cells matrix.race is empty, so ${RACE:+-race} adds nothing.
  • exclude entries remove the cells they match.
  • needs: [test] waits for every cell that runs.
  • A failed cell stops the others, as on GitHub: once a cell fails (after its retries), the cells that have not started never start, and running cells are cancelled. Jobs that need a cancelled cell are skipped, unless they run whatever happened (if: always()). Write fail-fast: false to let every cell run to its end.
  • A matrix job has no outputs:.

Limits: at most 256 cells; the product of the lists may be up to 1,024 before exclude removes cells.