Skip to content

Commit

Permalink
Add example and docs for array param with defaults 📜
Browse files Browse the repository at this point in the history
While working on (finally) updating the array result and object
param/result TEPs (tektoncd/community#479
tektoncd/community#477) I realized I hadn't
included an example of how to specify defaults for the new format, so I
looked for an example of how we currently do this for arrays, but we had
none! Hopefully now we do :D
  • Loading branch information
bobcatfish committed Mar 18, 2022
1 parent 4186dc9 commit fee9d2c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
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
args: [
"echo",
"$(params.array-to-echo[*])",
"$(params.another-array-to-echo[*])",
"$(params.string-to-echo)",
]

0 comments on commit fee9d2c

Please sign in to comment.