Skip to content

Commit 1b043c5

Browse files
committed
fix: set PipelineURL for cached pipelines to resolve relative task paths
When multiple PipelineRuns reference the same remote pipeline with relative task paths, the second PipelineRun fails because the PipelineURL is not set when retrieving the pipeline from cache. This causes assembleTaskFQDNs to receive an empty PipelineURL, which returns relative paths unchanged (e.g., '../../common/tasks/hello.yaml'). The go-github library then rejects these paths with 'path must not contain ..' error. The fix sets PipelineURL when using cached pipelines, ensuring relative task paths are resolved correctly for all PipelineRuns. Fixes: SRVKP-10604 Signed-off-by: Shubham Mathur <shumathu@redhat.com>
1 parent fc4ee2f commit 1b043c5

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

pkg/resolve/remote.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ func resolveRemoteResources(ctx context.Context, rt *matcher.RemoteTasks, types
129129
}
130130
// add the pipeline to the Resources fetched for the Event
131131
fetchedResourcesForEvent.Pipelines[remotePipeline] = pipeline
132-
// add the pipeline URL to the run specific Resources
133-
fetchedResourcesForPipelineRun.PipelineURL = remotePipeline
134132
}
133+
// set the pipeline URL for relative task path resolution (used by both cached and newly fetched)
134+
fetchedResourcesForPipelineRun.PipelineURL = remotePipeline
135135
}
136136
}
137137
pipelineTasks := []string{}

pkg/resolve/remote_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,53 @@ func TestRemote(t *testing.T) {
244244
"remote-pipeline-with-relative-tasks-1.yaml",
245245
},
246246
},
247+
{
248+
name: "multiple pipelineruns sharing same remote pipeline with relative tasks, pipeline and tasks all resolve",
249+
pipelineruns: []*tektonv1.PipelineRun{
250+
ttkn.MakePR(randomPipelineRunName, map[string]string{
251+
apipac.Pipeline: remotePipelineURL,
252+
},
253+
tektonv1.PipelineRunSpec{
254+
PipelineRef: &tektonv1.PipelineRef{
255+
Name: remotePipelineName,
256+
},
257+
},
258+
),
259+
ttkn.MakePR(randomPipelineRunName+"-second", map[string]string{
260+
apipac.Pipeline: remotePipelineURL, // SAME URL as first PipelineRun
261+
},
262+
tektonv1.PipelineRunSpec{
263+
PipelineRef: &tektonv1.PipelineRef{
264+
Name: remotePipelineName,
265+
},
266+
},
267+
),
268+
},
269+
remoteURLS: map[string]map[string]string{
270+
remotePipelineURL: {
271+
"body": string(pipelineWithRelativeTaskRefYamlB),
272+
"code": "200",
273+
},
274+
remoteTaskURL + "-a": {
275+
"body": string(singleRelativeTaskBa),
276+
"code": "200",
277+
},
278+
remoteTaskURL + "-b": {
279+
"body": string(singleRelativeTaskBb),
280+
"code": "200",
281+
},
282+
remoteTaskURL + "-c": {
283+
"body": string(singleRelativeTaskBc),
284+
"code": "200",
285+
},
286+
},
287+
expectedTaskSpec: taskFromPipelineSpec,
288+
expectedLogsSnippets: []string{},
289+
expectedPipelineRun: []string{
290+
"remote-pipeline-with-relative-tasks.yaml",
291+
"remote-pipeline-with-relative-tasks-same-pipeline.yaml",
292+
},
293+
},
247294
{
248295
name: "remote pipeline with remote task in pipeline overridden from pipelinerun",
249296
pipelineruns: []*tektonv1.PipelineRun{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: tekton.dev/v1
2+
kind: PipelineRun
3+
metadata:
4+
annotations:
5+
pipelinesascode.tekton.dev/pipeline: http://remote/remote-pipeline
6+
generateName: pipelinerun-abc-second-
7+
spec:
8+
pipelineSpec:
9+
tasks:
10+
- name: remote-task-a
11+
taskSpec:
12+
steps:
13+
- name: step1
14+
image: scratch
15+
command:
16+
- "true"
17+
- name: remote-task-b
18+
taskSpec:
19+
steps:
20+
- name: step1
21+
image: scratch
22+
command:
23+
- "true"
24+
- name: remote-task-c
25+
taskSpec:
26+
steps:
27+
- name: step1
28+
image: scratch
29+
command:
30+
- "true"
31+
finally: []

0 commit comments

Comments
 (0)