Skip to article content
FrontendXLesson 09 / 16

Matrix Builds

Take one task-board application from local tests to a real delivery pipeline: continuous integration fundamentals, push and pull-request quality gates, lint, type-check, unit, component and end-to-end gates, dependency caching, matrix builds, artifacts and checksums, secrets and supply-chain security, release promotion, staging and production, rollback and observability.

intermediate · about 25 minutes · 4 exercises

  • Predict
  • Implement
  • Debug
  • Interview

What you will be able to do

#
  • Define a matrix with fail-fast and max-parallel.
  • Supply every referenced value in an include entry.
  • Decide when a matrix is worth its cost.

Overview

#

One job definition, many combinations

A matrix runs the same job across a set of values, such as several Node versions or operating systems. It replaces copy-pasted jobs with one definition and a list of combinations.

snippet.yaml
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      max-parallel: 4
      matrix:
        os: [ubuntu-latest, macos-latest]
        node: [18, 20, 22]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - run: corepack enable && pnpm install --frozen-lockfile
      - run: pnpm test

fail-fast and max-parallel

With fail-fast: true (the default), the first failing combination cancels the others. That saves resources but hides whether the other combinations would also fail. Set fail-fast: false when you need the full failure picture. max-parallel caps how many combinations run at once so a large matrix does not exhaust the runner pool.

include and exclude

include adds or augments combinations, and exclude removes ones you do not need. An include entry that adds a new combination must supply every value the job references, or the job fails with an undefined value.

Cost

A matrix multiplies cost. Three Node versions across two operating systems is six jobs. Add a matrix only when the extra combinations catch real defects, such as a version-specific behavior or a platform-specific path bug. A matrix that always passes on every combination is expensive insurance, not verification.

Sandbox boundary

The browser sandbox runs one JavaScript environment, not a matrix of Node versions. It can compute the list of combinations from a matrix definition, which is the pure part of the logic.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Implement

    Add a matrix that tests Node 18, 20 and 22 with fail-fast disabled and at most two combinations in parallel.

    starter.yaml
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          - run: pnpm test
    

    Reveal the reference answer
    reference.yaml
    jobs:
      test:
        runs-on: ubuntu-latest
        strategy:
          fail-fast: false
          max-parallel: 2
          matrix:
            node: [18, 20, 22]
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-node@v4
            with:
              node-version: ${{ matrix.node }}
          - run: corepack enable && pnpm install --frozen-lockfile
          - run: pnpm test

    Authored expected output: A test job with a three-entry Node matrix, fail-fast false and max-parallel two.

    fail-fast false reports every failing version, and max-parallel keeps resource use bounded.

  2. Exercise 2Debug

    This matrix include entry references matrix.node but never defines it, so the job fails. Fix the entry.

    starter.yaml
          matrix:
            os: [ubuntu-latest]
            include:
              - os: ubuntu-latest
    

    Reveal the reference answer
    reference.yaml
          matrix:
            os: [ubuntu-latest]
            node: [20]
            include:
              - os: ubuntu-latest
                node: 20
    

    Authored expected output: The include entry supplies both os and node, matching the keys the job references.

    An include entry must provide every matrix value the job uses. A missing key resolves to an empty value and fails the job.

  3. Exercise 3Predict

    A three-entry matrix runs with fail-fast true. Entry two fails. What happens to entry three?

    Choose the best answer
  4. Exercise 4Interview

    When is a matrix worth the cost, and when is it waste?

    Reveal the reference answer
    reference.text
    A matrix is worth it when the combinations catch real defects, such as version-specific behavior or platform path bugs, or when the project officially supports several runtimes. It is waste when every combination always passes and no defect has ever been found by the extra axes. Keep only the axes that have caught something or that match a support promise.

    Authored expected output: A correct answer ties matrix axes to real defects or a support promise and warns against always-green axes.

    A matrix is verification only when its axes can fail. Axes that never fail are cost without signal.

Common misconceptions

#
  • fail-fast reports every failing combination.
  • An include entry can omit keys the job uses.
  • More matrix axes always mean better verification.

Follow-up practice

#
  • cicd-10-artifacts-checksums

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.