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

TEP-0090: Support both matrix and params in a PipelineTask #5050

Merged
merged 1 commit into from
Jun 29, 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
33 changes: 33 additions & 0 deletions docs/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ weight: 11
- [Configuring a Matrix](#configuring-a-matrix)
- [Concurrency Control](#concurrency-control)
- [Parameters](#parameters)
- [Specifying both `params` and `matrix` in a `PipelineTask`](#specifying-both-params-and-matrix-in-a-pipelinetask)
- [Context Variables](#context-variables)
- [Results](#results)
- [Specifying Results in a Matrix](#specifying-results-in-a-matrix)
Expand Down Expand Up @@ -112,6 +113,38 @@ A `Parameter` can be passed to either the `matrix` or `params` field, not both.
For further details on specifying `Parameters` in the `Pipeline` and passing them to
`PipelineTasks`, see [documentation](pipelines.md#specifying-parameters).

#### Specifying both `params` and `matrix` in a `PipelineTask`

In the example below, the *test* `Task` takes *browser* and *platform* `Parameters` of type
`"string"`. A `Pipeline` used to run the `Task` on three browsers (using `matrix`) and one
platform (using `params`) would be specified as such and execute three `TaskRuns`:

```yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: platform-browser-tests
spec:
tasks:
- name: fetch-repository
taskRef:
name: git-clone
...
- name: test
matrix:
- name: browser
value:
- chrome
- safari
- firefox
params:
- name: platform
value: linux
taskRef:
name: browser-test
...
```

### Context Variables

Similarly to the `Parameters` in the `Params` field, the `Parameters` in the `Matrix` field will accept
Expand Down
12 changes: 12 additions & 0 deletions examples/v1beta1/pipelineruns/alpha/pipelinerun-with-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ spec:
- firefox
taskRef:
name: platform-browsers
- name: matrix-and-params
matrix:
- name: platform
value:
- linux
- mac
- windows
params:
- name: browser
value: chrome
taskRef:
name: platform-browsers
4 changes: 1 addition & 3 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,7 @@ func (c *Reconciler) createTaskRun(ctx context.Context, taskRunName string, para

rpt.PipelineTask = resources.ApplyPipelineTaskContexts(rpt.PipelineTask)
taskRunSpec := pr.GetTaskRunSpec(rpt.PipelineTask.Name)
if len(params) == 0 {
params = rpt.PipelineTask.Params
}
params = append(params, rpt.PipelineTask.Params...)
tr = &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: taskRunName,
Expand Down
39 changes: 38 additions & 1 deletion pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7513,11 +7513,12 @@ spec:
params:
- name: platform
- name: browser
- name: version
steps:
- name: echo
image: alpine
script: |
echo "$(params.platform) and $(params.browser)"
echo "$(params.platform) and $(params.browser) and $(params.version)"
`)

expectedTaskRuns := []*v1beta1.TaskRun{
Expand All @@ -7531,6 +7532,8 @@ spec:
value: linux
- name: browser
value: chrome
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7547,6 +7550,8 @@ spec:
value: mac
- name: browser
value: chrome
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7563,6 +7568,8 @@ spec:
value: windows
- name: browser
value: chrome
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7579,6 +7586,8 @@ spec:
value: linux
- name: browser
value: safari
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7595,6 +7604,8 @@ spec:
value: mac
- name: browser
value: safari
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7611,6 +7622,8 @@ spec:
value: windows
- name: browser
value: safari
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7627,6 +7640,8 @@ spec:
value: linux
- name: browser
value: firefox
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7643,6 +7658,8 @@ spec:
value: mac
- name: browser
value: firefox
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand All @@ -7659,6 +7676,8 @@ spec:
value: windows
- name: browser
value: firefox
- name: version
value: v0.33.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand Down Expand Up @@ -7698,6 +7717,9 @@ spec:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
`, "p-dag")),
expectedPipelineRun: parse.MustParsePipelineRun(t, `
metadata:
Expand Down Expand Up @@ -7727,6 +7749,9 @@ status:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
conditions:
- type: Succeeded
status: "Unknown"
Expand Down Expand Up @@ -7787,6 +7812,8 @@ spec:
value: linux
- name: browser
value: chrome
- name: version
value: v0.22.0
taskRef:
name: mytask
finally:
Expand All @@ -7804,6 +7831,9 @@ spec:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
`, "p-finally")),
tr: mustParseTaskRunWithObjectMeta(t,
taskRunObjectMeta("pr-unmatrixed-pt", "foo",
Expand All @@ -7815,6 +7845,8 @@ spec:
value: linux
- name: browser
value: chrome
- name: version
value: v0.22.0
resources: {}
serviceAccountName: test-sa
taskRef:
Expand Down Expand Up @@ -7847,6 +7879,8 @@ status:
value: linux
- name: browser
value: chrome
- name: version
value: v0.22.0
taskRef:
name: mytask
finally:
Expand All @@ -7864,6 +7898,9 @@ status:
- chrome
- safari
- firefox
params:
- name: version
value: v0.33.0
conditions:
- type: Succeeded
status: "Unknown"
Expand Down