From 8f427a84c7a975d3e5d9dea5b046dc583d8a5a33 Mon Sep 17 00:00:00 2001 From: Nikhil Thomas Date: Fri, 6 Mar 2020 17:01:10 +0530 Subject: [PATCH] Add params section to Pipelinerun doc Adds params section to Pipelinerun doc to explain how to specify params in a Pipelinerun Spec Add examples in `examples/v1alpha1/pipelineruns` and `examples/v1beta1/pipelineruns` Fixes https://github.com/tektoncd/pipeline/issues/2153 Signed-off-by: Nikhil Thomas --- docs/pipelineruns.md | 21 ++++- .../pipelineruns/pipelinerun-with-params.yaml | 92 +++++++++++++++++++ .../pipelineruns/pipelinerun-with-params.yaml | 90 ++++++++++++++++++ 3 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 examples/v1alpha1/pipelineruns/pipelinerun-with-params.yaml create mode 100644 examples/v1beta1/pipelineruns/pipelinerun-with-params.yaml diff --git a/docs/pipelineruns.md b/docs/pipelineruns.md index 145c4393a50..17216a9cc80 100644 --- a/docs/pipelineruns.md +++ b/docs/pipelineruns.md @@ -13,12 +13,13 @@ Creation of a `PipelineRun` will trigger the creation of - [Syntax](#syntax) - [Resources](#resources) + - [Params](#params) - [Service account](#service-account) - [Service accounts](#service-accounts) - [Pod Template](#pod-template) - [Workspaces](#workspaces) - [Cancelling a PipelineRun](#cancelling-a-pipelinerun) -- [Examples](https://github.com/tektoncd/pipeline/tree/master/examples/pipelineruns) +- [Examples](https://github.com/tektoncd/pipeline/tree/master/examples/v1beta1/pipelineruns) - [Logs](logs.md) - [LimitRanges](#limitranges) @@ -39,6 +40,7 @@ following fields: - Optional: - [`resources`](#resources) - Specifies which [`PipelineResources`](resources.md) to use for this `PipelineRun`. + - [`params`](#params) - Specifies which params to be passed to the pipeline specified/referenced by this pipeline run. - [`serviceAccountName`](#service-account) - Specifies a `ServiceAccount` resource object that enables your build to run with the defined authentication information. When a `ServiceAccount` isn't specified, the `default-service-account` @@ -171,6 +173,23 @@ spec: value: gcr.io/christiewilson-catfactory/leeroy-app ``` +### Params + +While writing a Pipelinerun, we can specify params that need to be bound to +the input params of the pipeline specified/referenced by the Pipelinerun. + +This means that a Pipeline can be run with different input params, by writing Pipelineruns +which bound different input values to the Pipeline params. + +```yaml +spec: + params: + - name: pl-param-x + value: "100" + - name: pl-param-y + value: "500" +``` + ### Service Account Specifies the `name` of a `ServiceAccount` resource object. Use the diff --git a/examples/v1alpha1/pipelineruns/pipelinerun-with-params.yaml b/examples/v1alpha1/pipelineruns/pipelinerun-with-params.yaml new file mode 100644 index 00000000000..2674b9cd4db --- /dev/null +++ b/examples/v1alpha1/pipelineruns/pipelinerun-with-params.yaml @@ -0,0 +1,92 @@ +apiVersion: tekton.dev/v1alpha1 +kind: Pipeline +metadata: + name: pipeline-with-params +spec: + params: + - name: pl-param-x + type: string + default: "1" + - name: pl-param-y + type: string + default: "1" + tasks: + - name: sum-params + taskRef: + name: sum-params + params: + - name: a + value: "$(params.pl-param-x)" + - name: b + value: "$(params.pl-param-y)" + - name: multiply-params + taskRef: + name: multiply-params + params: + - name: a + value: "$(params.pl-param-x)" + - name: b + value: "$(params.pl-param-y)" +--- +apiVersion: tekton.dev/v1alpha1 +kind: Task +metadata: + name: sum-params + annotations: + description: | + A simple task that sums the two provided integers +spec: + inputs: + params: + - name: a + type: string + default: "1" + description: The first integer + - name: b + type: string + default: "1" + description: The second integer + steps: + - name: sum + image: bash:latest + script: | + #!/usr/bin/env bash + echo -n $(( "$(inputs.params.a)" + "$(inputs.params.b)" )) +--- +apiVersion: tekton.dev/v1alpha1 +kind: Task +metadata: + name: multiply-params + annotations: + description: | + A simple task that multiplies the two provided integers +spec: + inputs: + params: + - name: a + type: string + default: "1" + description: The first integer + - name: b + type: string + default: "1" + description: The second integer + steps: + - name: product + image: bash:latest + script: | + #!/usr/bin/env bash + echo -n $(( "$(inputs.params.a)" * "$(inputs.params.b)" )) +--- +apiVersion: tekton.dev/v1alpha1 +kind: PipelineRun +metadata: + name: pipelinerun-with-params +spec: + params: + - name: pl-param-x + value: "100" + - name: pl-param-y + value: "500" + pipelineRef: + name: pipeline-with-params diff --git a/examples/v1beta1/pipelineruns/pipelinerun-with-params.yaml b/examples/v1beta1/pipelineruns/pipelinerun-with-params.yaml new file mode 100644 index 00000000000..faae67fd819 --- /dev/null +++ b/examples/v1beta1/pipelineruns/pipelinerun-with-params.yaml @@ -0,0 +1,90 @@ +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: pipeline-with-params +spec: + params: + - name: pl-param-x + type: string + default: "1" + - name: pl-param-y + type: string + default: "1" + tasks: + - name: sum-params + taskRef: + name: sum-params + params: + - name: a + value: "$(params.pl-param-x)" + - name: b + value: "$(params.pl-param-y)" + - name: multiply-params + taskRef: + name: multiply-params + params: + - name: a + value: "$(params.pl-param-x)" + - name: b + value: "$(params.pl-param-y)" +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: sum-params + annotations: + description: | + A simple task that sums the two provided integers +spec: + params: + - name: a + type: string + default: "1" + description: The first integer + - name: b + type: string + default: "1" + description: The second integer + steps: + - name: sum + image: bash:latest + script: | + #!/usr/bin/env bash + echo -n $(( "$(inputs.params.a)" + "$(inputs.params.b)" )) +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: multiply-params + annotations: + description: | + A simple task that multiplies the two provided integers +spec: + params: + - name: a + type: string + default: "1" + description: The first integer + - name: b + type: string + default: "1" + description: The second integer + steps: + - name: product + image: bash:latest + script: | + #!/usr/bin/env bash + echo -n $(( "$(inputs.params.a)" * "$(inputs.params.b)" )) +--- +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: pipelinerun-with-params +spec: + params: + - name: pl-param-x + value: "100" + - name: pl-param-y + value: "500" + pipelineRef: + name: pipeline-with-params