Skip to content

RHDEVDOCS 6177 explain optional workspaces #84147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: pipelines-docs-main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions modules/op-about-workspace.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,31 @@ spec:
<1> Specifies the list of pipeline workspaces for which volume binding will be provided in the pipeline run.
<2> The name of the workspace in the pipeline for which the volume is being provided.
<3> Specifies a volume claim template that creates a persistent volume claim to define the storage volume for the workspace.

In the definition of a task, you can use the `$(workspaces.source.path)` variable to refer to the path where the workspace is mounted.

Normally, if you define a workspace in a pipeline or task and then don't provide the workspace in the pipeline run or task run, the run fails. However, you can mark a workspace as _optional_ by adding an `optional: true` field to the definition of the workspace. In this case, you do not have to provide the workspace in the pipeline run or task run. If the workspaces is not provided, the `$(workspaces.source.path)` variable has an empty value.

The following code snippet defines a task with an optional workspace.

[source,yaml]
----
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: demo-optional-workspace
spec:
workspaces:
- name: output
optional: true
steps:
- name: echo
image: registry.access.redhat.com/ubi9/ubi-micro
env:
- name: OUTPUT
value: $(workspaces.output.path)
script: |
#!/usr/bin/env bash
echo "hello world"
if [[ "" != $OUTPUT ]]; then echo "hello world" >> $OUTPUT/hello ; fi
----