Skip to main content
Matrix is used to fan out Tasks in a Pipeline by generating combinations of parameters. This allows you to run the same Task multiple times with different parameter values in parallel.
Matrix is a beta feature. Set enable-api-fields to "beta" to use this feature.

Overview

A Matrix allows you to:
  • Generate parameter combinations automatically using Matrix.Params
  • Specify explicit combinations using Matrix.Include
  • Fan out both regular Tasks and Custom Tasks
  • Control concurrency of parallel executions
  • Aggregate results from all fanned-out TaskRuns

Generating Combinations

Use Matrix.Params to automatically generate all combinations of the specified parameter values:
This generates four combinations:

Adding Explicit Combinations

Use Matrix.Include to add specific combinations or augment existing ones:
The first include clause adds the url parameter to all combinations with platform: linux. The second adds a new combination:

Using Include Without Params

You can use Matrix.Include alone to specify exact combinations without auto-generation:
This creates exactly three TaskRuns with the specified parameters.

Complete Example

Here’s a complete example that creates nine TaskRuns from a matrix of platforms and browsers:

Concurrency Control

The default maximum number of TaskRuns from a Matrix is 256. Configure this in config-defaults.yaml:
If a Matrix generates more TaskRuns than the configured maximum, the Pipeline validation will fail.

Using Parameters

String and Array Replacements

Matrix.Params supports replacements from Pipeline parameters:

Combining Params and Matrix

You can use both params and matrix in a PipelineTask:
This executes three TaskRuns, all with platform: linux and different browser values.
A parameter can be passed to either matrix or params, but not both.

Working with Results

Consuming Results in Matrix

You can use results from previous Tasks to generate matrix combinations:

Emitting Results from Matrix

Each TaskRun in a fanned-out PipelineTask can emit string results, which are aggregated into an array:

Context Variables

Matrix Length

Access the total number of TaskRuns created by a matrix:

Aggregated Results Length

Access the length of aggregated result arrays:

Display Names

Customize the display name of each matrix instance using parameters:
The displayName appears in pipelineRun.status.childReferences:
You can also specify names in matrix.include[] which take precedence over displayName:

Retries

When a PipelineTask with a Matrix specifies retries, each individual TaskRun is retried independently:
This creates three TaskRuns, each retried once upon failure.

Advanced Example: Go Build Matrix

Here’s a complex example using both Matrix.Params and Matrix.Include for Go builds across architectures:
This generates seven TaskRuns with the following combinations:

Matrix with Custom Tasks

Matrix also works with Custom Tasks, creating multiple Runs instead of TaskRuns:
This example uses the CEL Custom Task and creates eight Runs with different CEL expressions.