Skip to content

Commit b54fa32

Browse files
Merge pull request #1510 from JordanGoasdoue/chore-finally-uses-sourceui
chore: processUsesSteps now handle ps.Finally tasks too
2 parents bb1159d + 82755c1 commit b54fa32

File tree

5 files changed

+358
-2
lines changed

5 files changed

+358
-2
lines changed

pkg/triggerconfig/inrepo/load_pipelinerun.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/pkg/errors"
15+
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
1516
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718
"sigs.k8s.io/yaml"
@@ -256,8 +257,22 @@ func processUsesSteps(resolver *UsesResolver, prs *tektonv1beta1.PipelineRun) er
256257
if ps == nil {
257258
return nil
258259
}
259-
for i := range ps.Tasks {
260-
pt := &ps.Tasks[i]
260+
tasksAndFinally := [][]v1beta1.PipelineTask{
261+
ps.Tasks,
262+
ps.Finally,
263+
}
264+
for i := range tasksAndFinally {
265+
pipelineTasks := tasksAndFinally[i]
266+
if err := processUsesStepsHelper(resolver, prs, pipelineTasks); err != nil {
267+
return err
268+
}
269+
}
270+
return nil
271+
}
272+
273+
func processUsesStepsHelper(resolver *UsesResolver, prs *tektonv1beta1.PipelineRun, pipelineTasks []tektonv1beta1.PipelineTask) error {
274+
for i := range pipelineTasks {
275+
pt := &pipelineTasks[i]
261276
if pt.TaskSpec != nil {
262277
ts := &pt.TaskSpec.TaskSpec
263278
clearStepTemplateImage := false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Reuse steps in a task inherit a 'finally' block
2+
3+
This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individually the steps in task
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: PipelineRun
3+
metadata:
4+
name: common
5+
spec:
6+
pipelineSpec:
7+
tasks:
8+
- name: common
9+
taskSpec:
10+
steps:
11+
- image: common-image
12+
name: common-build
13+
env:
14+
- name: FOO
15+
value: foo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: PipelineRun
3+
metadata:
4+
creationTimestamp: null
5+
name: cheese
6+
spec:
7+
params:
8+
- name: BUILD_ID
9+
value: ""
10+
- name: JOB_NAME
11+
value: ""
12+
- name: JOB_SPEC
13+
value: ""
14+
- name: JOB_TYPE
15+
value: ""
16+
- name: PULL_BASE_REF
17+
value: ""
18+
- name: PULL_BASE_SHA
19+
value: ""
20+
- name: PULL_NUMBER
21+
value: ""
22+
- name: PULL_PULL_REF
23+
value: ""
24+
- name: PULL_PULL_SHA
25+
value: ""
26+
- name: PULL_REFS
27+
value: ""
28+
- name: REPO_NAME
29+
value: ""
30+
- name: REPO_OWNER
31+
value: ""
32+
- name: REPO_URL
33+
value: ""
34+
pipelineSpec:
35+
finally:
36+
- name: from-build-pack-finally
37+
params:
38+
- name: BUILD_ID
39+
value: $(params.BUILD_ID)
40+
- name: JOB_NAME
41+
value: $(params.JOB_NAME)
42+
- name: JOB_SPEC
43+
value: $(params.JOB_SPEC)
44+
- name: JOB_TYPE
45+
value: $(params.JOB_TYPE)
46+
- name: PULL_BASE_REF
47+
value: $(params.PULL_BASE_REF)
48+
- name: PULL_BASE_SHA
49+
value: $(params.PULL_BASE_SHA)
50+
- name: PULL_NUMBER
51+
value: $(params.PULL_NUMBER)
52+
- name: PULL_PULL_REF
53+
value: $(params.PULL_PULL_REF)
54+
- name: PULL_PULL_SHA
55+
value: $(params.PULL_PULL_SHA)
56+
- name: PULL_REFS
57+
value: $(params.PULL_REFS)
58+
- name: REPO_NAME
59+
value: $(params.REPO_NAME)
60+
- name: REPO_OWNER
61+
value: $(params.REPO_OWNER)
62+
- name: REPO_URL
63+
value: $(params.REPO_URL)
64+
taskSpec:
65+
metadata: {}
66+
params:
67+
- description: the unique build number
68+
name: BUILD_ID
69+
type: string
70+
- description: the name of the job which is the trigger context name
71+
name: JOB_NAME
72+
type: string
73+
- description: the specification of the job
74+
name: JOB_SPEC
75+
type: string
76+
- description: '''the kind of job: postsubmit or presubmit'''
77+
name: JOB_TYPE
78+
type: string
79+
- description: the base git reference of the pull request
80+
name: PULL_BASE_REF
81+
type: string
82+
- description: the git sha of the base of the pull request
83+
name: PULL_BASE_SHA
84+
type: string
85+
- default: ""
86+
description: git pull request number
87+
name: PULL_NUMBER
88+
type: string
89+
- default: ""
90+
description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head'
91+
name: PULL_PULL_REF
92+
type: string
93+
- default: ""
94+
description: git revision to checkout (branch, tag, sha, ref…)
95+
name: PULL_PULL_SHA
96+
type: string
97+
- description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head'
98+
name: PULL_REFS
99+
type: string
100+
- description: git repository name
101+
name: REPO_NAME
102+
type: string
103+
- description: git repository owner (user or organisation)
104+
name: REPO_OWNER
105+
type: string
106+
- description: git url to clone
107+
name: REPO_URL
108+
type: string
109+
spec: null
110+
stepTemplate:
111+
env:
112+
- name: BUILD_ID
113+
value: $(params.BUILD_ID)
114+
- name: JOB_NAME
115+
value: $(params.JOB_NAME)
116+
- name: JOB_SPEC
117+
value: $(params.JOB_SPEC)
118+
- name: JOB_TYPE
119+
value: $(params.JOB_TYPE)
120+
- name: PULL_BASE_REF
121+
value: $(params.PULL_BASE_REF)
122+
- name: PULL_BASE_SHA
123+
value: $(params.PULL_BASE_SHA)
124+
- name: PULL_NUMBER
125+
value: $(params.PULL_NUMBER)
126+
- name: PULL_PULL_REF
127+
value: $(params.PULL_PULL_REF)
128+
- name: PULL_PULL_SHA
129+
value: $(params.PULL_PULL_SHA)
130+
- name: PULL_REFS
131+
value: $(params.PULL_REFS)
132+
- name: REPO_NAME
133+
value: $(params.REPO_NAME)
134+
- name: REPO_OWNER
135+
value: $(params.REPO_OWNER)
136+
- name: REPO_URL
137+
value: $(params.REPO_URL)
138+
name: ""
139+
resources: {}
140+
steps:
141+
- env:
142+
- name: FOO
143+
value: finally
144+
image: common-image
145+
name: common-build
146+
resources: {}
147+
params:
148+
- description: the unique build number
149+
name: BUILD_ID
150+
type: string
151+
- description: the name of the job which is the trigger context name
152+
name: JOB_NAME
153+
type: string
154+
- description: the specification of the job
155+
name: JOB_SPEC
156+
type: string
157+
- description: '''the kind of job: postsubmit or presubmit'''
158+
name: JOB_TYPE
159+
type: string
160+
- description: the base git reference of the pull request
161+
name: PULL_BASE_REF
162+
type: string
163+
- description: the git sha of the base of the pull request
164+
name: PULL_BASE_SHA
165+
type: string
166+
- default: ""
167+
description: git pull request number
168+
name: PULL_NUMBER
169+
type: string
170+
- default: ""
171+
description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head'
172+
name: PULL_PULL_REF
173+
type: string
174+
- default: ""
175+
description: git revision to checkout (branch, tag, sha, ref…)
176+
name: PULL_PULL_SHA
177+
type: string
178+
- description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head'
179+
name: PULL_REFS
180+
type: string
181+
- description: git repository name
182+
name: REPO_NAME
183+
type: string
184+
- description: git repository owner (user or organisation)
185+
name: REPO_OWNER
186+
type: string
187+
- description: git url to clone
188+
name: REPO_URL
189+
type: string
190+
tasks:
191+
- name: from-build-pack
192+
params:
193+
- name: BUILD_ID
194+
value: $(params.BUILD_ID)
195+
- name: JOB_NAME
196+
value: $(params.JOB_NAME)
197+
- name: JOB_SPEC
198+
value: $(params.JOB_SPEC)
199+
- name: JOB_TYPE
200+
value: $(params.JOB_TYPE)
201+
- name: PULL_BASE_REF
202+
value: $(params.PULL_BASE_REF)
203+
- name: PULL_BASE_SHA
204+
value: $(params.PULL_BASE_SHA)
205+
- name: PULL_NUMBER
206+
value: $(params.PULL_NUMBER)
207+
- name: PULL_PULL_REF
208+
value: $(params.PULL_PULL_REF)
209+
- name: PULL_PULL_SHA
210+
value: $(params.PULL_PULL_SHA)
211+
- name: PULL_REFS
212+
value: $(params.PULL_REFS)
213+
- name: REPO_NAME
214+
value: $(params.REPO_NAME)
215+
- name: REPO_OWNER
216+
value: $(params.REPO_OWNER)
217+
- name: REPO_URL
218+
value: $(params.REPO_URL)
219+
taskSpec:
220+
metadata: {}
221+
params:
222+
- description: the unique build number
223+
name: BUILD_ID
224+
type: string
225+
- description: the name of the job which is the trigger context name
226+
name: JOB_NAME
227+
type: string
228+
- description: the specification of the job
229+
name: JOB_SPEC
230+
type: string
231+
- description: '''the kind of job: postsubmit or presubmit'''
232+
name: JOB_TYPE
233+
type: string
234+
- description: the base git reference of the pull request
235+
name: PULL_BASE_REF
236+
type: string
237+
- description: the git sha of the base of the pull request
238+
name: PULL_BASE_SHA
239+
type: string
240+
- default: ""
241+
description: git pull request number
242+
name: PULL_NUMBER
243+
type: string
244+
- default: ""
245+
description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head'
246+
name: PULL_PULL_REF
247+
type: string
248+
- default: ""
249+
description: git revision to checkout (branch, tag, sha, ref…)
250+
name: PULL_PULL_SHA
251+
type: string
252+
- description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head'
253+
name: PULL_REFS
254+
type: string
255+
- description: git repository name
256+
name: REPO_NAME
257+
type: string
258+
- description: git repository owner (user or organisation)
259+
name: REPO_OWNER
260+
type: string
261+
- description: git url to clone
262+
name: REPO_URL
263+
type: string
264+
spec: null
265+
stepTemplate:
266+
env:
267+
- name: BUILD_ID
268+
value: $(params.BUILD_ID)
269+
- name: JOB_NAME
270+
value: $(params.JOB_NAME)
271+
- name: JOB_SPEC
272+
value: $(params.JOB_SPEC)
273+
- name: JOB_TYPE
274+
value: $(params.JOB_TYPE)
275+
- name: PULL_BASE_REF
276+
value: $(params.PULL_BASE_REF)
277+
- name: PULL_BASE_SHA
278+
value: $(params.PULL_BASE_SHA)
279+
- name: PULL_NUMBER
280+
value: $(params.PULL_NUMBER)
281+
- name: PULL_PULL_REF
282+
value: $(params.PULL_PULL_REF)
283+
- name: PULL_PULL_SHA
284+
value: $(params.PULL_PULL_SHA)
285+
- name: PULL_REFS
286+
value: $(params.PULL_REFS)
287+
- name: REPO_NAME
288+
value: $(params.REPO_NAME)
289+
- name: REPO_OWNER
290+
value: $(params.REPO_OWNER)
291+
- name: REPO_URL
292+
value: $(params.REPO_URL)
293+
name: ""
294+
resources: {}
295+
steps:
296+
- env:
297+
- name: FOO
298+
value: foo
299+
image: common-image
300+
name: common-build
301+
resources: {}
302+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: PipelineRun
3+
metadata:
4+
name: cheese
5+
spec:
6+
pipelineSpec:
7+
tasks:
8+
- name: from-build-pack
9+
taskSpec:
10+
steps:
11+
- image: uses:./test_data/load_pipelinerun/pipeline-finally-uses/common.yaml
12+
name: common-build
13+
finally:
14+
- name: from-build-pack-finally
15+
taskSpec:
16+
steps:
17+
- image: uses:./test_data/load_pipelinerun/pipeline-finally-uses/common.yaml
18+
name: common-build
19+
env:
20+
- name: FOO
21+
value: finally

0 commit comments

Comments
 (0)