Repository: tektoncd/pipeline (language: go)

Issue:
When a duplicate parameter name is encountered in the pipeline, there is an issue with inaccurate path reporting.
# Expected Behavior

```
admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: params names must be unique, the same param: abc is defined multiple times at:
spec.tasks[0].params[1].name
```

# Actual Behavior

```
admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: parameter names must be unique, the parameter "abc" is also defined at:
spec.tasks.params[0][1].name, spec.tasks[0].params[1].name
```

# Steps to Reproduce the Problem

1. Create a pipeline
```
cat <<EOF | kubectl create -f -
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: pipeline
spec:
  tasks:
    - name: name-1
      taskRef:
        name: hi
        kind: Task
      params:
        - name: "abc"
          value: ""
        - name: "abc"
          value: ""
EOF
```

# Additional Info

- Kubernetes version:

```
Client Version: v1.29.1
Server Version: v1.27.7
```

- Tekton Pipeline version:

```
v0.56.0
```


<!-- Any other additional information -->



Discussion / hints:

Fix patch:
diff --git a/pkg/apis/pipeline/v1/pipeline_validation.go b/pkg/apis/pipeline/v1/pipeline_validation.go
index 164046412e8..e98fff7823b 100644
--- a/pkg/apis/pipeline/v1/pipeline_validation.go
+++ b/pkg/apis/pipeline/v1/pipeline_validation.go
@@ -382,7 +382,7 @@ func validatePipelineTaskParameterUsage(tasks []PipelineTask, params ParamSpecs)
 	}
 	errs = errs.Also(validatePipelineParametersVariables(tasks, "params", allParamNames, arrayParamNames, objectParameterNameKeys))
 	for i, task := range tasks {
-		errs = errs.Also(task.Params.validateDuplicateParameters().ViaFieldIndex("params", i))
+		errs = errs.Also(task.Params.validateDuplicateParameters().ViaField("params").ViaIndex(i))
 	}
 	return errs
 }
diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation.go b/pkg/apis/pipeline/v1beta1/pipeline_validation.go
index 1179249626d..075d49afff9 100644
--- a/pkg/apis/pipeline/v1beta1/pipeline_validation.go
+++ b/pkg/apis/pipeline/v1beta1/pipeline_validation.go
@@ -400,7 +400,7 @@ func validatePipelineTaskParameterUsage(tasks []PipelineTask, params ParamSpecs)
 	}
 	errs = errs.Also(validatePipelineParametersVariables(tasks, "params", allParamNames, arrayParamNames, objectParameterNameKeys))
 	for i, task := range tasks {
-		errs = errs.Also(task.Params.validateDuplicateParameters().ViaFieldIndex("params", i))
+		errs = errs.Also(task.Params.validateDuplicateParameters().ViaField("params").ViaIndex(i))
 	}
 	return errs
 }


Test patch:
diff --git a/pkg/apis/pipeline/v1/pipeline_validation_test.go b/pkg/apis/pipeline/v1/pipeline_validation_test.go
index 4ee7acc508c..55c7b121d87 100644
--- a/pkg/apis/pipeline/v1/pipeline_validation_test.go
+++ b/pkg/apis/pipeline/v1/pipeline_validation_test.go
@@ -220,6 +220,52 @@ func TestPipeline_Validate_Failure(t *testing.T) {
 			Message: `non-existent variable in "$(params.doesnotexist)"`,
 			Paths:   []string{"spec.finally[0].steps[0].script"},
 		},
+	}, {
+		name: "invalid duplicate parameter in pipeline task",
+		p: &Pipeline{
+			ObjectMeta: metav1.ObjectMeta{Name: "pipeline"},
+			Spec: PipelineSpec{
+				Tasks: []PipelineTask{{
+					Name: "pipeline-task",
+					TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
+						Steps: []Step{{
+							Name:    "some-step",
+							Image:   "some-image",
+							Command: []string{"cmd"},
+						}},
+					}},
+				}},
+				Finally: []PipelineTask{{
+					Name: "invalid-pipeline-task",
+					Params: Params{
+						{
+							Name: "name",
+							Value: ParamValue{
+								Type:      ParamTypeString,
+								StringVal: "",
+							},
+						},
+						{
+							Name: "name",
+							Value: ParamValue{
+								Type:      ParamTypeString,
+								StringVal: "",
+							},
+						},
+					},
+					TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
+						Steps: []Step{{
+							Name:  "some-step",
+							Image: "some-image",
+						}},
+					}},
+				}},
+			},
+		},
+		expectedError: apis.FieldError{
+			Message: `parameter names must be unique, the parameter "name" is also defined at`,
+			Paths:   []string{"spec.finally[0].params[1].name"},
+		},
 	}, {
 		name: "invalid task with pipelineRef and pipelineSpec",
 		wc:   cfgtesting.EnableAlphaAPIFields,
diff --git a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
index 9f37d95586e..a67351ad277 100644
--- a/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
+++ b/pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
@@ -222,6 +222,52 @@ func TestPipeline_Validate_Failure(t *testing.T) {
 			Message: `non-existent variable in "$(params.doesnotexist)"`,
 			Paths:   []string{"spec.finally[0].steps[0].script"},
 		},
+	}, {
+		name: "invalid duplicate parameter in pipeline task",
+		p: &Pipeline{
+			ObjectMeta: metav1.ObjectMeta{Name: "pipeline"},
+			Spec: PipelineSpec{
+				Tasks: []PipelineTask{{
+					Name: "pipeline-task",
+					TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
+						Steps: []Step{{
+							Name:    "some-step",
+							Image:   "some-image",
+							Command: []string{"cmd"},
+						}},
+					}},
+				}},
+				Finally: []PipelineTask{{
+					Name: "invalid-pipeline-task",
+					Params: Params{
+						{
+							Name: "name",
+							Value: ParamValue{
+								Type:      ParamTypeString,
+								StringVal: "",
+							},
+						},
+						{
+							Name: "name",
+							Value: ParamValue{
+								Type:      ParamTypeString,
+								StringVal: "",
+							},
+						},
+					},
+					TaskSpec: &EmbeddedTask{TaskSpec: TaskSpec{
+						Steps: []Step{{
+							Name:  "some-step",
+							Image: "some-image",
+						}},
+					}},
+				}},
+			},
+		},
+		expectedError: apis.FieldError{
+			Message: `parameter names must be unique, the parameter "name" is also defined at`,
+			Paths:   []string{"spec.finally[0].params[1].name"},
+		},
 	}, {
 		name: "invalid task with pipelineRef and pipelineSpec",
 		wc:   cfgtesting.EnableAlphaAPIFields,