diff --git a/docs/pipelines.md b/docs/pipelines.md index de9bae82891..3acf19ad8d6 100644 --- a/docs/pipelines.md +++ b/docs/pipelines.md @@ -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`. diff --git a/docs/tasks.md b/docs/tasks.md index 1214b60f4f8..1e9ee168e1e 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -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).** diff --git a/examples/v1beta1/taskruns/array-default.yaml b/examples/v1beta1/taskruns/array-default.yaml new file mode 100644 index 00000000000..f3829f9309a --- /dev/null +++ b/examples/v1beta1/taskruns/array-default.yaml @@ -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)", + ] \ No newline at end of file