From 4c45dbd601f0bf7ab68f79a7d33ee248ad02bd43 Mon Sep 17 00:00:00 2001 From: Christie Wilson Date: Wed, 26 Jan 2022 09:36:56 -0800 Subject: [PATCH] =?UTF-8?q?Add=20example=20and=20docs=20for=20array=20para?= =?UTF-8?q?m=20with=20defaults=20=F0=9F=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While working on (finally) updating the array result and object param/result TEPs (https://github.com/tektoncd/community/pull/479 https://github.com/tektoncd/community/pull/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 --- docs/pipelines.md | 2 ++ docs/tasks.md | 20 ++++++++++++ examples/v1beta1/taskruns/array-default.yaml | 32 ++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 examples/v1beta1/taskruns/array-default.yaml diff --git a/docs/pipelines.md b/docs/pipelines.md index 2c76aa6c287..906d669ae33 100644 --- a/docs/pipelines.md +++ b/docs/pipelines.md @@ -184,6 +184,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