diff --git a/pkg/apis/pipeline/v1beta1/task_validation.go b/pkg/apis/pipeline/v1beta1/task_validation.go index a43e05b54f4..acea12ba00d 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation.go +++ b/pkg/apis/pipeline/v1beta1/task_validation.go @@ -321,8 +321,12 @@ func ValidateParameterVariables(steps []Step, params []ParamSpec) *apis.FieldErr parameterNames := sets.NewString() arrayParameterNames := sets.NewString() objectParamSpecs := []ParamSpec{} - + var errs *apis.FieldError for _, p := range params { + // validate no duplicate names + if parameterNames.Has(p.Name) { + errs = errs.Also(apis.ErrGeneric("parameter appears more than once", "").ViaFieldKey("params", p.Name)) + } parameterNames.Insert(p.Name) if p.Type == ParamTypeArray { arrayParameterNames.Insert(p.Name) @@ -332,7 +336,7 @@ func ValidateParameterVariables(steps []Step, params []ParamSpec) *apis.FieldErr } } - errs := validateVariables(steps, "params", parameterNames) + errs = errs.Also(validateVariables(steps, "params", parameterNames)) errs = errs.Also(validateArrayUsage(steps, "params", arrayParameterNames)) return errs.Also(validateObjectUsage(steps, objectParamSpecs)) } diff --git a/pkg/apis/pipeline/v1beta1/task_validation_test.go b/pkg/apis/pipeline/v1beta1/task_validation_test.go index c51e59a30ad..a19e50f11af 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/task_validation_test.go @@ -529,6 +529,26 @@ func TestTaskSpecValidateError(t *testing.T) { Paths: []string{"params"}, Details: "Names: \nMust only contain alphanumeric characters, hyphens (-), underscores (_), and dots (.)\nMust begin with a letter or an underscore (_)", }, + }, { + name: "duplicated param names", + fields: fields{ + Params: []v1beta1.ParamSpec{{ + Name: "foo", + Type: v1beta1.ParamTypeString, + Description: "parameter", + Default: v1beta1.NewArrayOrString("value1"), + }, { + Name: "foo", + Type: v1beta1.ParamTypeString, + Description: "parameter", + Default: v1beta1.NewArrayOrString("value2"), + }}, + Steps: validSteps, + }, + expectedError: apis.FieldError{ + Message: `parameter appears more than once`, + Paths: []string{"params[foo]"}, + }, }, { name: "invalid param type", fields: fields{