-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit enables producing Results from Matrixed PipelineTasks so that they can be used in subsequent PipelineTasks. A Pipeline author can now declare a matrixed taskRun that emits results of type string that are fanned out over multiple taskRuns and aggregated into an array of results that can then be consumed by another pipelineTask using the syntax `$(tasks.<pipelineTaskName>.results.<resultName>[*])`. This commit also introduces 2 context variables to 1) Access Matrix Combinations Length using `tasks.<pipelineTaskName>.matrix.length` and 2) Access Aggregated Results Length using `tasks.<pipelineTaskName>.matrix.<resultName>.length` Note: Currently, we don't support consuming a single instance/combinations of results. Authors must consume the entire aggregated results array. Co-authored-by: Priti Desai <[email protected]>
- Loading branch information
1 parent
c9ff759
commit eb7d0ec
Showing
24 changed files
with
3,344 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
examples/v1/pipelineruns/alpha/pipelinerun-with-matrix-context-variables.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: validate-matrix-result-length | ||
spec: | ||
params: | ||
- name: matrixlength | ||
type: string | ||
steps: | ||
- name: validate | ||
image: alpine | ||
args: ["$(params.matrixlength)"] | ||
script: | | ||
#!/usr/bin/env sh | ||
echo "Validating the length of the matrix context variable" | ||
echo "The length of the matrix is 3" | ||
if [ "$(params.matrixlength)" != 3 ]; then | ||
echo "Error: expected matrix to have the length 3 but has length $(params.matrixlength)" | ||
exit 1 | ||
fi | ||
echo "Done validating the length of the matrix context variable" | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: validate-matrix-results-length | ||
spec: | ||
params: | ||
- name: matrixresultslength-1 | ||
type: string | ||
- name: matrixresultslength-2 | ||
type: string | ||
steps: | ||
- name: validate | ||
image: alpine | ||
script: | | ||
#!/usr/bin/env sh | ||
echo "Validating the length of the matrix results context variable" | ||
echo "The length of the matrix results are $(params.matrixresultslength-1) and $(params.matrixresultslength-2)" | ||
if [ "$(params.matrixresultslength-1)" != 3 ]; then | ||
echo "Error: expected matrix results to have the length 3 but has length $(params.matrixresultslength-1)" | ||
exit 1 | ||
fi | ||
if [ "$(params.matrixresultslength-2)" != 1 ]; then | ||
echo "Error: expected matrix results to have the length 1 but has length $(params.matrixresultslength-2)" | ||
exit 1 | ||
fi | ||
echo "Done validating the length of the matrix context variable" | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: taskwithresults | ||
spec: | ||
params: | ||
- name: IMAGE | ||
- name: DIGEST | ||
default: "" | ||
results: | ||
- name: IMAGE-DIGEST | ||
- name: IMAGE-URL | ||
steps: | ||
- name: produce-results | ||
image: bash:latest | ||
script: | | ||
#!/usr/bin/env bash | ||
echo "Building image for $(params.IMAGE)" | ||
echo -n "$(params.DIGEST)" | sha256sum | tee $(results.IMAGE-DIGEST.path) | ||
if [ -z $(params.DIGEST) ]; then | ||
echo -n "$(params.DIGEST)" | sha256sum | tee $(results.IMAGE-URL.path) | ||
fi | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: matrix-context-variables- | ||
spec: | ||
taskRunTemplate: | ||
serviceAccountName: "default" | ||
pipelineSpec: | ||
tasks: | ||
- name: matrix-emitting-results | ||
matrix: | ||
include: | ||
- name: build-1 | ||
params: | ||
- name: IMAGE | ||
value: image-1 | ||
- name: DIGEST | ||
value: path/to/Dockerfile1 | ||
- name: build-2 | ||
params: | ||
- name: IMAGE | ||
value: image-2 | ||
- name: DIGEST | ||
value: path/to/Dockerfile2 | ||
- name: build-3 | ||
params: | ||
- name: IMAGE | ||
value: image-3 | ||
taskRef: | ||
name: taskwithresults | ||
kind: Task | ||
- name: matrixed-echo-length | ||
runAfter: | ||
- matrix-emitting-results | ||
params: | ||
- name: matrixlength | ||
value: $(tasks.matrix-emitting-results.matrix.length) | ||
taskRef: | ||
name: validate-matrix-result-length | ||
kind: Task | ||
- name: matrixed-echo-results-length | ||
runAfter: | ||
- matrix-emitting-results | ||
params: | ||
- name: matrixresultslength-1 | ||
value: $(tasks.matrix-emitting-results.matrix.IMAGE-DIGEST.length) | ||
- name: matrixresultslength-2 | ||
value: $(tasks.matrix-emitting-results.matrix.IMAGE-URL.length) | ||
taskRef: | ||
name: validate-matrix-results-length | ||
kind: Task |
110 changes: 110 additions & 0 deletions
110
examples/v1/pipelineruns/alpha/pipelinerun-with-matrix-emitting-results.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: echostringurl | ||
spec: | ||
params: | ||
- name: url | ||
type: string | ||
steps: | ||
- name: echo | ||
image: alpine | ||
script: | | ||
echo "$(params.url)" | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: validate-array-url | ||
spec: | ||
params: | ||
- name: url | ||
type: array | ||
steps: | ||
- name: validate | ||
image: ubuntu | ||
args: ["$(params.url[*])"] | ||
script: | | ||
#!/usr/bin/env bash | ||
args=("$@") | ||
URLS=( ) | ||
URLS[0]="https://api.example/get-report/linux-chrome" | ||
URLS[1]="https://api.example/get-report/mac-chrome" | ||
URLS[2]="https://api.example/get-report/windows-chrome" | ||
URLS[3]="https://api.example/get-report/linux-safari" | ||
URLS[4]="https://api.example/get-report/mac-safari" | ||
URLS[5]="https://api.example/get-report/windows-safari" | ||
URLS[6]="https://api.example/get-report/linux-firefox" | ||
URLS[7]="https://api.example/get-report/mac-firefox" | ||
URLS[8]="https://api.example/get-report/windows-firefox" | ||
for i in "${!URLS[@]}"; do | ||
if [ "${URLS[$i]}" != ${args[$i]} ]; then | ||
echo "Error: expected url to be ${URLS[$i]}, but got ${args[$i]}" | ||
exit 1 | ||
fi | ||
echo "Done validating the url: ${args[$i]}" | ||
done | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
name: task-producing-results | ||
spec: | ||
params: | ||
- name: platform | ||
default: "" | ||
- name: browser | ||
default: "" | ||
results: | ||
- name: report-url | ||
type: string | ||
steps: | ||
- name: produce-report-url | ||
image: alpine | ||
script: | | ||
echo "Running tests on $(params.platform)-$(params.browser)" | ||
echo -n "https://api.example/get-report/$(params.platform)-$(params.browser)" | tee $(results.report-url.path) | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: PipelineRun | ||
metadata: | ||
generateName: platforms-with-results | ||
spec: | ||
taskRunTemplate: | ||
serviceAccountName: "default" | ||
pipelineSpec: | ||
results: | ||
- name: pr-result-1 | ||
value: $(tasks.matrix-emitting-results.results.report-url[*]) | ||
tasks: | ||
- name: matrix-emitting-results | ||
matrix: | ||
params: | ||
- name: platform | ||
value: | ||
- linux | ||
- mac | ||
- windows | ||
- name: browser | ||
value: | ||
- chrome | ||
- safari | ||
- firefox | ||
taskRef: | ||
name: task-producing-results | ||
kind: Task | ||
- name: task-consuming-results | ||
taskRef: | ||
name: validate-array-url | ||
kind: Task | ||
params: | ||
- name: url | ||
value: $(tasks.matrix-emitting-results.results.report-url[*]) | ||
- name: matrix-consuming-results | ||
taskRef: | ||
name: echostringurl | ||
kind: Task | ||
matrix: | ||
params: | ||
- name: url | ||
value: $(tasks.matrix-emitting-results.results.report-url[*]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.