Example
How It Works
Declare Workspaces in Task
The task declares two optional workspaces:
source-code and extra-config. The optional: true flag means the task can run even if these workspaces aren’t provided.Provide Workspaces in TaskRun
The TaskRun provides only the
source-code workspace, backed by an emptyDir volume. The extra-config workspace is intentionally not provided.Check Workspace Availability
The step uses
$(workspaces.NAME.bound) to check if a workspace was provided. This allows the task to behave differently based on what’s available.Workspace Variables
Tekton provides several variables for each workspace:$(workspaces.NAME.path)- The filesystem path where the workspace is mounted$(workspaces.NAME.bound)- “true” if the workspace was provided, “false” otherwise$(workspaces.NAME.volume)- The name of the volume backing the workspace
Workspace Types
Workspaces can be backed by different volume types:- emptyDir: Temporary storage that exists only for the TaskRun
- persistentVolumeClaim: Persistent storage that survives across runs
- configMap: Read-only configuration data
- secret: Read-only sensitive data
Expected Output
- The
source-codeworkspace is provided and detected - The
extra-configworkspace is not provided (as expected)
Key Concepts
- Workspaces: Named volumes that can be mounted into task steps
- Optional Workspaces: Tasks can declare workspaces as optional using
optional: true - Workspace Binding: The process of providing a volume for a workspace at runtime
- Shared Storage: All steps in a task share the same workspace mounts
Next Steps
- See workspace usage in pipelines
- Learn about task results