Skip to content

Commit

Permalink
Return error if there are multiple same name params
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NavidZ authored and tekton-robot committed Jun 16, 2020
1 parent db66eca commit 648cff3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ func validatePipelineParameterVariables(tasks []PipelineTask, params []ParamSpec
}
}

if _, ok := parameterNames[p.Name]; ok {
return apis.ErrGeneric("parameter appears more than once", fmt.Sprintf("spec.params.%s", p.Name))
}
// Add parameter name to parameterNames, and to arrayParameterNames if type is array.
parameterNames[p.Name] = struct{}{}
if p.Type == ParamTypeArray {
Expand Down
33 changes: 33 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,39 @@ func TestValidatePipelineParameterVariables_Failure(t *testing.T) {
Name: "a-param", Value: ArrayOrString{Type: ParamTypeArray, ArrayVal: []string{"value: $(params.baz[*])", "last"}},
}},
}},
}, {
name: "multiple string parameters with the same name",
params: []ParamSpec{{
Name: "baz", Type: ParamTypeString,
}, {
Name: "baz", Type: ParamTypeString,
}},
tasks: []PipelineTask{{
Name: "foo",
TaskRef: &TaskRef{Name: "foo-task"},
}},
}, {
name: "multiple array parameters with the same name",
params: []ParamSpec{{
Name: "baz", Type: ParamTypeArray,
}, {
Name: "baz", Type: ParamTypeArray,
}},
tasks: []PipelineTask{{
Name: "foo",
TaskRef: &TaskRef{Name: "foo-task"},
}},
}, {
name: "multiple different type parameters with the same name",
params: []ParamSpec{{
Name: "baz", Type: ParamTypeArray,
}, {
Name: "baz", Type: ParamTypeString,
}},
tasks: []PipelineTask{{
Name: "foo",
TaskRef: &TaskRef{Name: "foo-task"},
}},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 648cff3

Please sign in to comment.