@@ -298,55 +298,41 @@ func ApplyWorkspaces(p *v1.PipelineSpec, pr *v1.PipelineRun) *v1.PipelineSpec {
298
298
return ApplyReplacements (p , replacements , map [string ][]string {}, map [string ]map [string ]string {})
299
299
}
300
300
301
- // ApplyReplacements replaces placeholders for declared parameters with the specified replacements.
302
- func ApplyReplacements (p * v1.PipelineSpec , replacements map [string ]string , arrayReplacements map [string ][]string , objectReplacements map [string ]map [string ]string ) * v1.PipelineSpec {
303
- p = p .DeepCopy ()
304
-
305
- for i := range p .Tasks {
306
- p .Tasks [i ].Params = p .Tasks [i ].Params .ReplaceVariables (replacements , arrayReplacements , objectReplacements )
307
- if p .Tasks [i ].IsMatrixed () {
308
- p .Tasks [i ].Matrix .Params = p .Tasks [i ].Matrix .Params .ReplaceVariables (replacements , arrayReplacements , nil )
309
- for j := range p .Tasks [i ].Matrix .Include {
310
- p .Tasks [i ].Matrix .Include [j ].Params = p .Tasks [i ].Matrix .Include [j ].Params .ReplaceVariables (replacements , nil , nil )
301
+ // replaceVariablesInPipelineTasks handles variable replacement for a slice of PipelineTasks in-place
302
+ func replaceVariablesInPipelineTasks (tasks []v1.PipelineTask , replacements map [string ]string ,
303
+ arrayReplacements map [string ][]string , objectReplacements map [string ]map [string ]string ) {
304
+ for i := range tasks {
305
+ tasks [i ].Params = tasks [i ].Params .ReplaceVariables (replacements , arrayReplacements , objectReplacements )
306
+ if tasks [i ].IsMatrixed () {
307
+ tasks [i ].Matrix .Params = tasks [i ].Matrix .Params .ReplaceVariables (replacements , arrayReplacements , nil )
308
+ for j := range tasks [i ].Matrix .Include {
309
+ tasks [i ].Matrix .Include [j ].Params = tasks [i ].Matrix .Include [j ].Params .ReplaceVariables (replacements , nil , nil )
311
310
}
312
311
} else {
313
- p . Tasks [i ].DisplayName = substitution .ApplyReplacements (p . Tasks [i ].DisplayName , replacements )
312
+ tasks [i ].DisplayName = substitution .ApplyReplacements (tasks [i ].DisplayName , replacements )
314
313
}
315
- for j := range p . Tasks [i ].Workspaces {
316
- p . Tasks [i ].Workspaces [j ].SubPath = substitution .ApplyReplacements (p . Tasks [i ].Workspaces [j ].SubPath , replacements )
314
+ for j := range tasks [i ].Workspaces {
315
+ tasks [i ].Workspaces [j ].SubPath = substitution .ApplyReplacements (tasks [i ].Workspaces [j ].SubPath , replacements )
317
316
}
318
- p . Tasks [i ].When = p . Tasks [i ].When .ReplaceVariables (replacements , arrayReplacements )
319
- if p . Tasks [i ].TaskRef != nil {
320
- if p . Tasks [i ].TaskRef .Params != nil {
321
- p . Tasks [i ].TaskRef .Params = p . Tasks [i ].TaskRef .Params .ReplaceVariables (replacements , arrayReplacements , objectReplacements )
317
+ tasks [i ].When = tasks [i ].When .ReplaceVariables (replacements , arrayReplacements )
318
+ if tasks [i ].TaskRef != nil {
319
+ if tasks [i ].TaskRef .Params != nil {
320
+ tasks [i ].TaskRef .Params = tasks [i ].TaskRef .Params .ReplaceVariables (replacements , arrayReplacements , objectReplacements )
322
321
}
323
- p . Tasks [i ].TaskRef .Name = substitution .ApplyReplacements (p . Tasks [i ].TaskRef .Name , replacements )
322
+ tasks [i ].TaskRef .Name = substitution .ApplyReplacements (tasks [i ].TaskRef .Name , replacements )
324
323
}
325
- p .Tasks [i ] = propagateParams (p .Tasks [i ], replacements , arrayReplacements , objectReplacements )
324
+ tasks [i ].OnError = v1 .PipelineTaskOnErrorType (substitution .ApplyReplacements (string (tasks [i ].OnError ), replacements ))
325
+ tasks [i ] = propagateParams (tasks [i ], replacements , arrayReplacements , objectReplacements )
326
326
}
327
+ }
327
328
328
- for i := range p .Finally {
329
- p .Finally [i ].Params = p .Finally [i ].Params .ReplaceVariables (replacements , arrayReplacements , objectReplacements )
330
- if p .Finally [i ].IsMatrixed () {
331
- p .Finally [i ].Matrix .Params = p .Finally [i ].Matrix .Params .ReplaceVariables (replacements , arrayReplacements , nil )
332
- for j := range p .Finally [i ].Matrix .Include {
333
- p .Finally [i ].Matrix .Include [j ].Params = p .Finally [i ].Matrix .Include [j ].Params .ReplaceVariables (replacements , nil , nil )
334
- }
335
- } else {
336
- p .Finally [i ].DisplayName = substitution .ApplyReplacements (p .Finally [i ].DisplayName , replacements )
337
- }
338
- for j := range p .Finally [i ].Workspaces {
339
- p .Finally [i ].Workspaces [j ].SubPath = substitution .ApplyReplacements (p .Finally [i ].Workspaces [j ].SubPath , replacements )
340
- }
341
- p .Finally [i ].When = p .Finally [i ].When .ReplaceVariables (replacements , arrayReplacements )
342
- if p .Finally [i ].TaskRef != nil {
343
- if p .Finally [i ].TaskRef .Params != nil {
344
- p .Finally [i ].TaskRef .Params = p .Finally [i ].TaskRef .Params .ReplaceVariables (replacements , arrayReplacements , objectReplacements )
345
- }
346
- p .Finally [i ].TaskRef .Name = substitution .ApplyReplacements (p .Finally [i ].TaskRef .Name , replacements )
347
- }
348
- p .Finally [i ] = propagateParams (p .Finally [i ], replacements , arrayReplacements , objectReplacements )
349
- }
329
+ // ApplyReplacements replaces placeholders for declared parameters with the specified replacements.
330
+ func ApplyReplacements (p * v1.PipelineSpec , replacements map [string ]string , arrayReplacements map [string ][]string , objectReplacements map [string ]map [string ]string ) * v1.PipelineSpec {
331
+ p = p .DeepCopy ()
332
+
333
+ // Replace variables in Tasks and Finally tasks
334
+ replaceVariablesInPipelineTasks (p .Tasks , replacements , arrayReplacements , objectReplacements )
335
+ replaceVariablesInPipelineTasks (p .Finally , replacements , arrayReplacements , objectReplacements )
350
336
351
337
return p
352
338
}
0 commit comments