Skip to content

Commit 648cff3

Browse files
NavidZtekton-robot
authored andcommitted
Return error if there are multiple same name params
Right now pipeline accept multiple parameters with the same name. This sometime causes the pipeline to not finish. This change adds a simple check and returns error when there are multiple parameters with the same name in the spec.params.
1 parent db66eca commit 648cff3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/apis/pipeline/v1beta1/pipeline_validation.go

+3
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ func validatePipelineParameterVariables(tasks []PipelineTask, params []ParamSpec
341341
}
342342
}
343343

344+
if _, ok := parameterNames[p.Name]; ok {
345+
return apis.ErrGeneric("parameter appears more than once", fmt.Sprintf("spec.params.%s", p.Name))
346+
}
344347
// Add parameter name to parameterNames, and to arrayParameterNames if type is array.
345348
parameterNames[p.Name] = struct{}{}
346349
if p.Type == ParamTypeArray {

pkg/apis/pipeline/v1beta1/pipeline_validation_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,39 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) {
916916
Name: "a-param", Value: ArrayOrString{Type: ParamTypeArray, ArrayVal: []string{"value: $(params.baz[*])", "last"}},
917917
}},
918918
}},
919+
}, {
920+
name: "multiple string parameters with the same name",
921+
params: []ParamSpec{{
922+
Name: "baz", Type: ParamTypeString,
923+
}, {
924+
Name: "baz", Type: ParamTypeString,
925+
}},
926+
tasks: []PipelineTask{{
927+
Name: "foo",
928+
TaskRef: &TaskRef{Name: "foo-task"},
929+
}},
930+
}, {
931+
name: "multiple array parameters with the same name",
932+
params: []ParamSpec{{
933+
Name: "baz", Type: ParamTypeArray,
934+
}, {
935+
Name: "baz", Type: ParamTypeArray,
936+
}},
937+
tasks: []PipelineTask{{
938+
Name: "foo",
939+
TaskRef: &TaskRef{Name: "foo-task"},
940+
}},
941+
}, {
942+
name: "multiple different type parameters with the same name",
943+
params: []ParamSpec{{
944+
Name: "baz", Type: ParamTypeArray,
945+
}, {
946+
Name: "baz", Type: ParamTypeString,
947+
}},
948+
tasks: []PipelineTask{{
949+
Name: "foo",
950+
TaskRef: &TaskRef{Name: "foo-task"},
951+
}},
919952
}}
920953
for _, tt := range tests {
921954
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)