@@ -17,24 +17,27 @@ limitations under the License.
1717package resources
1818
1919import (
20+ "context"
2021 "fmt"
2122 "strconv"
2223 "strings"
2324
25+ "github.com/tektoncd/pipeline/pkg/apis/config"
2426 "github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1"
2527
2628 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
2729 "github.com/tektoncd/pipeline/pkg/substitution"
2830)
2931
3032// ApplyParameters applies the params from a PipelineRun.Params to a PipelineSpec.
31- func ApplyParameters (p * v1beta1.PipelineSpec , pr * v1beta1.PipelineRun ) * v1beta1.PipelineSpec {
33+ func ApplyParameters (ctx context. Context , p * v1beta1.PipelineSpec , pr * v1beta1.PipelineRun ) * v1beta1.PipelineSpec {
3234 // This assumes that the PipelineRun inputs have been validated against what the Pipeline requests.
3335
3436 // stringReplacements is used for standard single-string stringReplacements, while arrayReplacements contains arrays
3537 // that need to be further processed.
3638 stringReplacements := map [string ]string {}
3739 arrayReplacements := map [string ][]string {}
40+ cfg := config .FromContextOrDefaults (ctx )
3841
3942 patterns := []string {
4043 "params.%s" ,
@@ -51,6 +54,12 @@ func ApplyParameters(p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) *v1beta1.
5154 }
5255 } else {
5356 for _ , pattern := range patterns {
57+ // array indexing for param is alpha feature
58+ if cfg .FeatureFlags .EnableAPIFields == config .AlphaAPIFields {
59+ for i := 0 ; i < len (p .Default .ArrayVal ); i ++ {
60+ stringReplacements [fmt .Sprintf (pattern + "[%d]" , p .Name , i )] = p .Default .ArrayVal [i ]
61+ }
62+ }
5463 arrayReplacements [fmt .Sprintf (pattern , p .Name )] = p .Default .ArrayVal
5564 }
5665 }
@@ -64,6 +73,12 @@ func ApplyParameters(p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) *v1beta1.
6473 }
6574 } else {
6675 for _ , pattern := range patterns {
76+ // array indexing for param is alpha feature
77+ if cfg .FeatureFlags .EnableAPIFields == config .AlphaAPIFields {
78+ for i := 0 ; i < len (p .Value .ArrayVal ); i ++ {
79+ stringReplacements [fmt .Sprintf (pattern + "[%d]" , p .Name , i )] = p .Value .ArrayVal [i ]
80+ }
81+ }
6782 arrayReplacements [fmt .Sprintf (pattern , p .Name )] = p .Value .ArrayVal
6883 }
6984 }
0 commit comments