Workspaces allow Tasks to declare parts of the filesystem that need to be provided at runtime by TaskRuns. A TaskRun can make these parts of the filesystem available in many ways.
Overview
Workspaces are similar to Volumes except that they allow a Task author to defer to users and their TaskRuns when deciding which class of storage to use.
Key Purposes
Workspaces can serve the following purposes:
- Storage of inputs and/or outputs
- Sharing data among
Tasks - A mount point for credentials held in
Secrets - A mount point for configurations held in
ConfigMaps - A mount point for common tools shared by an organization
- A cache of build artifacts that speed up jobs
Workspaces in Tasks and TaskRuns
Tasks specify where a Workspace resides on disk for its Steps. At runtime, a TaskRun provides the specific details of the Volume that is mounted into that Workspace.
This separation of concerns allows for a lot of flexibility. For example, in isolation, a single TaskRun might simply provide an emptyDir volume that mounts quickly and disappears at the end of the run. In a more complex system, however, a TaskRun might use a PersistentVolumeClaim which is pre-populated with data for the Task to process.
Workspaces in Pipelines and PipelineRuns
APipeline can use Workspaces to show how storage will be shared through its Tasks. For example, Task A might clone a source repository onto a Workspace and Task B might compile the code that it finds in that Workspace.
PipelineRuns provide the specific Volume information to use for the Workspaces used by each Pipeline. PipelineRuns have the added responsibility of ensuring that whatever Volume type they provide can be safely and correctly shared across multiple Tasks.
Optional Workspaces
BothTasks and Pipelines can declare a Workspace “optional”. When an optional Workspace is declared the TaskRun or PipelineRun may omit a Workspace Binding for that Workspace. The Task or Pipeline behaviour may change when the Binding is omitted.
Use Cases
- A
Taskmay optionally accept credentials to run authenticated commands - A
Pipelinemay accept optional configuration that changes the linting or compilation parameters used - An optional build cache may be provided to speed up compile times
Using Workspaces in Tasks
To configure one or moreWorkspaces in a Task, add a workspaces list with each entry using the following fields:
A unique string identifier that can be used to refer to the workspace.
An informative string describing the purpose of the Workspace.
A boolean declaring whether the Task will write to the Workspace.
A boolean indicating whether a TaskRun can omit the Workspace.
A path to a location on disk where the workspace will be available to Steps. Defaults to
/workspace/<name>.Example Task with Workspace
Workspace Variables in Tasks
The following variables make information aboutWorkspaces available to Tasks:
$(workspaces.<name>.path)- Specifies the path to a Workspace$(workspaces.<name>.bound)- Eithertrueorfalse, specifies whether a workspace was bound$(workspaces.<name>.claim)- Specifies the name of the PersistentVolumeClaim used as a volume source$(workspaces.<name>.volume)- Specifies the name of the Volume provided for a Workspace
Mapping Workspaces in Tasks to TaskRuns
ATaskRun that executes a Task containing a workspaces list must bind those workspaces to actual physical Volumes.
TaskRun Workspace Fields
The name of the Workspace within the Task for which the Volume is being provided.
An optional subdirectory on the Volume to store data for that Workspace.
VolumeSource.
Example TaskRun with Workspaces
Using Workspaces in Pipelines
While individualTasks declare the Workspaces they need to run, the Pipeline decides which Workspaces are shared among its Tasks.
Example Pipeline with Workspaces
Include a
runAfter to define the order in which Tasks write to or read from a shared Workspace.Volume Sources
You can only use a single type ofVolumeSource per Workspace entry.
PersistentVolumeClaim
volumeClaimTemplate
Creates a new PersistentVolumeClaim for each PipelineRun or TaskRun:persistentVolumeClaim
References an existing PersistentVolumeClaim:emptyDir
Provides a temporary directory that only lives as long as the TaskRun:configMap
References a ConfigMap volume:configMapvolume sources are always mounted as read-only- The configMap must exist prior to submitting the TaskRun
- configMaps are size-limited to 1MB
secret
References a Secret volume:secretvolume sources are always mounted as read-only- The secret must exist prior to submitting the TaskRun
- secrets are size-limited to 1MB
projected
References a projected volume:projected volume sources are always mounted as read-only.Specifying Workspaces in PipelineRuns
For aPipelineRun to execute a Pipeline that includes one or more Workspaces, it needs to bind the Workspace names to volumes.
Example PipelineRun with Workspace
Access Modes and Storage Classes
Access Modes
APersistentVolumeClaim specifies an Access Mode. Available Access Modes are:
- ReadWriteOnce - Most commonly available. A volume can only be mounted on one Node at a time. The Affinity Assistant helps schedule all Tasks using the same PVC to the same Node.
- ReadOnlyMany - Read-only, less common in CI/CD pipelines. These volumes often need to be “prepared” with data before use.
- ReadWriteMany - Least commonly available. If available to all Nodes in your cluster, you may want to disable the Affinity Assistant.
Storage Classes
PersistentVolumeClaims specify a Storage Class for the underlying Persistent Volume. If a StorageClassName is not specified, the cluster-defined default Storage Class is used.