-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a short example of using optional workspaces in when expressions
We've just added support for optional workspaces but I forgot to include an example showing how to use them as part of a When Expression. This commit adds a PipelineRun example YAML showing use of a workspaces.<name>.bound variable in a when expression. I've also updated pipelines.md to mention that you can use a when expression to evaluate whether an optional workspace was bound or not and to provide a short example snippet of using the bound variables in a when expression.
- Loading branch information
1 parent
117dca2
commit 8ecaa29
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
examples/v1beta1/pipelineruns/using-optional-workspaces-in-when-expressions.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# This example demonstrates using the workspaces.<name>.bound variable | ||
# in a when expression to selectively run different portions of a Pipeline | ||
# based on the presence of an optional workspace. | ||
# | ||
# In the PipelineRun below an optional message-of-the-day workspace is accepted | ||
# by the Pipeline. If that workspace is provided then the print-motd task is | ||
# executed. If that workspace is not provided then a print-default-motd task | ||
# is run instead. We supply a ConfigMap for the workspace and so the print-motd | ||
# task ends up running and printing the contents of each entry in the ConfigMap. | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: test-motd | ||
data: | ||
message_1: "Hello, good morning!" | ||
message_2: "Hello, good evening!" | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: optional-workspace-when- | ||
spec: | ||
serviceAccountName: 'default' | ||
workspaces: | ||
- name: message-of-the-day | ||
configMap: | ||
name: test-motd | ||
pipelineSpec: | ||
workspaces: | ||
- name: message-of-the-day | ||
optional: true | ||
description: | | ||
If a workspace is provided here then every file at the root of the workspace | ||
will be printed. | ||
tasks: | ||
- name: print-motd | ||
when: | ||
- input: "$(workspaces.message-of-the-day.bound)" | ||
operator: in | ||
values: ["true"] | ||
workspaces: | ||
- name: message-of-the-day | ||
workspace: message-of-the-day | ||
taskSpec: | ||
workspaces: | ||
- name: message-of-the-day | ||
steps: | ||
- image: alpine | ||
script: | | ||
#!/usr/bin/env ash | ||
for f in "$(workspaces.message-of-the-day.path)"/* ; do | ||
echo "Message from $f:" | ||
cat "$f" | ||
echo "" # add newline | ||
done | ||
- name: print-default-motd | ||
when: | ||
- input: "$(workspaces.message-of-the-day.bound)" | ||
operator: in | ||
values: ["false"] | ||
taskSpec: | ||
steps: | ||
- name: print-default | ||
image: alpine | ||
script: | | ||
echo "No message-of-the-day workspace was provided. This is the default MOTD instead!" |