Skip to content
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

Add example and docs for array param with defaults 📜 #4518

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ For more information, see:

## Specifying `Parameters`

(See also [Specifying Parameters in Tasks](tasks.md#specifying-parameters))

You can specify global parameters, such as compilation flags or artifact names, that you want to supply
to the `Pipeline` at execution time. `Parameters` are passed to the `Pipeline` from its corresponding
`PipelineRun` and can replace template values specified within each `Task` in the `Pipeline`.
Expand Down
20 changes: 20 additions & 0 deletions docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,26 @@ spec:
value: "http://google.com"
```
Parameter declarations (within Tasks and Pipelines) can include default values which will be used if the parameter is
not specified, for example to specify defaults for both string params and array params
([full example](../examples/v1beta1/taskruns/array-default.yaml)) :
```yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: task-with-array-default
spec:
params:
- name: flags
type: array
default:
- "--set"
- "arg1=foo"
- "--randomflag"
- "--someotherflag"
```
### Specifying `Resources`

> :warning: **`PipelineResources` are [deprecated](deprecations.md#deprecation-table).**
Expand Down
32 changes: 32 additions & 0 deletions examples/v1beta1/taskruns/array-default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: array-with-default-
spec:
params:
- name: array-to-echo
value:
- "foo"
- "bar"
taskSpec:
params:
- name: array-to-echo
type: array
- name: another-array-to-echo
type: array
default:
- "foo-default"
- "bar-default"
- name: string-to-echo
type: string
default: "baz"
steps:
# this step should echo "foo bar foo-default bar-default baz"
- name: echo-params
image: bash:3.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: IMO, adding a comment that documents the fully-resolved echo that will be executed by the task post-parameter-resolution will clarify the example.

args: [
"echo",
"$(params.array-to-echo[*])",
"$(params.another-array-to-echo[*])",
"$(params.string-to-echo)",
]