Skip to main content
Tekton supports variable substitution to pass data dynamically within Tasks and Pipelines. This guide shows you how to use variables effectively in your workflows.

Overview

Variable substitution allows you to:
  • Access parameter values at runtime
  • Reference Task results in subsequent Tasks
  • Use context information about the TaskRun or PipelineRun
  • Access workspace paths and bound status
  • Retrieve exit codes from previous Steps
Tekton does not escape the contents of variables. Task authors are responsible for properly escaping a variable’s value according to the shell, image, or scripting language being used.

Basic Variable Syntax

Variables use the syntax $(variable.name) and can be referenced in most fields of a Task or Pipeline.

Parameter Variables

Access parameter values using:
Example:

Array Parameters

Access entire arrays or individual elements:
Array indexing is an alpha feature. Set enable-api-fields to alpha to use it.
Example:

Object Parameters

Access object parameter properties (alpha feature):

Pipeline Variables

Task Results

Reference results from previous Tasks:

Array Results

Access array results:
Example:

Object Results

Access object result properties:

Context Variables

Task Context Variables

Access information about the current Task and TaskRun:

Pipeline Context Variables

Access information about the current Pipeline and PipelineRun:

Workspace Variables

Access workspace information:

Results Variables

Writing Results

Write results to the path provided by Tekton:

Result Path Variables

Step Variables

Access exit codes from previous Steps:

Matrix Variables

Access matrix execution information:

Finally Task Variables

In finally tasks, access execution status:

Fields Supporting Variable Substitution

Not all fields support variable substitution. Key supported fields include:

Task Fields

  • spec.steps[].name
  • spec.steps[].image
  • spec.steps[].command
  • spec.steps[].args
  • spec.steps[].script
  • spec.steps[].env.value
  • spec.volumes[].name
  • spec.sidecars[].name
  • spec.sidecars[].image

Pipeline Fields

  • spec.tasks[].params[].value
  • spec.tasks[].workspaces[].subPath
  • spec.tasks[].when[].input
  • spec.tasks[].when[].values
  • spec.finally[].params[].value

Practical Examples

Using Parameters in Scripts

Chaining Task Results

Conditional Workspace Usage

Use variable substitution to make your Tasks and Pipelines reusable across different environments and use cases.