-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
pipelinerun-with-matrix-context-variables.yaml
123 lines (123 loc) · 3.68 KB
/
pipelinerun-with-matrix-context-variables.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: validate-matrix-result-length
spec:
params:
- name: matrixlength
type: string
steps:
- name: validate
image: mirror.gcr.io/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: mirror.gcr.io/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: mirror.gcr.io/bash
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