Skip to content

Commit

Permalink
Add support for array task results as matrix parameters
Browse files Browse the repository at this point in the history
fixes #5925

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer committed Jan 27, 2023
1 parent 03215a3 commit d034cd6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
30 changes: 9 additions & 21 deletions docs/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,40 +166,28 @@ Consuming `Results` from previous `TaskRuns` or `Runs` in a `Matrix`, which woul
`TaskRuns` or `Runs` from the fanned out `PipelineTask`, is supported. Producing `Results` in from a
`PipelineTask` with a `Matrix` is not yet supported - see [further details](#results-from-fanned-out-pipelinetasks).

`Matrix` supports Results of type String that are passed in individually:
`Matrix` supports Results of type String that are passed in individually, and of type Array, either individual
values by index or the entire array:

```yaml
tasks:
...
- name: task-4
- name: task-5
taskRef:
name: task-4
name: task-5
matrix:
params:
- name: values
value:
- (tasks.task-1.results.foo) # string
- (tasks.task-2.results.bar) # string
- (tasks.task-3.results.rad) # string
- $(tasks.task-1.results.foo) # string
- $(tasks.task-2.results.bar) # string
- $(tasks.task-3.results.rad[0]) # array index
- name: otherValues
value: $(tasks.task-4.results.someArray[*])
```
For further information, see the example in [`PipelineRun` with `Matrix` and `Results`][pr-with-matrix-and-results].

When we support `Results` of type Array at the `Pipeline` level, we will support passing Results into the `Matrix`.
> Note: Results of type Array are not yet supported in the Pipeline level.

```yaml
tasks:
...
- name: task-5
taskRef:
name: task-5
matrix:
params:
- name: values
value: (tasks.task-4.results.foo) # array
```

#### Results from fanned out PipelineTasks

Consuming `Results` from fanned out `PipelineTasks` will not be in the supported in the initial iteration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ spec:
- name: get-browsers
taskSpec:
results:
- name: one
- name: two
- name: three
- name: browsers
steps:
- name: echo
image: alpine
script: |
printf chrome | tee /tekton/results/one
printf safari | tee /tekton/results/two
printf firefox | tee /tekton/results/three
#!/usr/bin/env bash
echo -n "[\"chrome\",\"safari\",\"firefox\"]" | tee $(results.browsers.path)
- name: platforms-and-browsers-dag
matrix:
params:
Expand All @@ -58,8 +55,6 @@ spec:
- $(tasks.get-platforms.results.two)
- $(tasks.get-platforms.results.three)
- name: browser
value:
- $(tasks.get-browsers.results.one)
- $(tasks.get-browsers.results.two)
value: $(tasks.get-browsers.results.browsers[*])
taskRef:
name: platform-browsers
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func ApplyTaskResults(targets PipelineRunState, resolvedResultRefs ResolvedResul
pipelineTask := resolvedPipelineRunTask.PipelineTask.DeepCopy()
pipelineTask.Params = replaceParamValues(pipelineTask.Params, stringReplacements, arrayReplacements, objectReplacements)
if pipelineTask.IsMatrixed() {
pipelineTask.Matrix.Params = replaceParamValues(pipelineTask.Matrix.Params, stringReplacements, nil, nil)
pipelineTask.Matrix.Params = replaceParamValues(pipelineTask.Matrix.Params, stringReplacements, arrayReplacements, nil)
}
pipelineTask.WhenExpressions = pipelineTask.WhenExpressions.ReplaceWhenExpressionsVariables(stringReplacements, arrayReplacements)
if pipelineTask.TaskRef != nil && pipelineTask.TaskRef.Params != nil {
Expand Down
32 changes: 32 additions & 0 deletions pkg/reconciler/pipelinerun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,38 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) {
}}},
},
}},
}, {
name: "Test array result substitution on minimal variable substitution expression - matrix",
resolvedResultRefs: ResolvedResultRefs{{
Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"),
ResultReference: v1beta1.ResultRef{
PipelineTask: "aTask",
Result: "aResult",
},
FromTaskRun: "aTaskRun",
}},
targets: PipelineRunState{{
PipelineTask: &v1beta1.PipelineTask{
Name: "bTask",
TaskRef: &v1beta1.TaskRef{Name: "bTask"},
Matrix: &v1beta1.Matrix{
Params: []v1beta1.Param{{
Name: "bParam",
Value: *v1beta1.NewStructuredValues(`$(tasks.aTask.results.aResult[*])`),
}}},
},
}},
want: PipelineRunState{{
PipelineTask: &v1beta1.PipelineTask{
Name: "bTask",
TaskRef: &v1beta1.TaskRef{Name: "bTask"},
Matrix: &v1beta1.Matrix{
Params: []v1beta1.Param{{
Name: "bParam",
Value: *v1beta1.NewStructuredValues("arrayResultValueOne", "arrayResultValueTwo"),
}}},
},
}},
}, {
name: "Test array result substitution on minimal variable substitution expression - when expressions",
resolvedResultRefs: ResolvedResultRefs{{
Expand Down

0 comments on commit d034cd6

Please sign in to comment.