Repository: tektoncd/pipeline (language: go)

Issue:
A matrix task with no TaskRun to execute will cause an enum validation panic
# Expected Behavior

tekton-pipelines-controller is not panic, and the PipelineRun status is normal.

# Actual Behavior

tekton-pipelines-controller panic.

# Steps to Reproduce the Problem

1. enable `enable-param-enum`
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: feature-flags
data:
  enable-param-enum: "true"
```

2. run pipelinerun
```shell
cat <<'EOF' | kubectl create -f -
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
  name: matrix-pipelinerun
spec:
  pipelineSpec:
    params:
      - name: values
        type: array
        default: []
      - name: string
        type: string
        default: default
    tasks:
      - name: panic
        matrix:
          params:
            - name: value
              # This array must be empty
              value: "$(params.values[*])"
        params:
          - name: suffix
            # This parameter must reference the top-level parameter.
            value: $(params.string)
        taskSpec:
          params:
            - name: value
              type: string
            - name: suffix
              type: string
          steps:
            - name: echo
              image: alpine
              script: |
                #!/bin/bash
                echo "Hello $(params.value)"
EOF
```

# Additional Info

- Kubernetes version:

  **Output of `kubectl version`:**

```
Client Version: v1.32.0
Kustomize Version: v5.5.0
Server Version: v1.28.8
```

- Tekton Pipeline version:

  **Output of `tkn version` or `kubectl get pods -n tekton-pipelines -l app=tekton-pipelines-controller -o=jsonpath='{.items[0].metadata.labels.version}'`**

```
Client version: 0.39.0
Chains version: v0.23.0
Pipeline version: v0.66.0
Triggers version: v0.30.0
Dashboard version: v0.52.0
Operator version: v0.74.0
```


<!-- Any other additional information -->
The bug exists in version v0.56 LTS and later, theoretically starting from 0.54.



Discussion / hints:

Fix patch:
diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
index 7f980d1005a..c7dc1a1ab44 100644
--- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
+++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
@@ -848,6 +848,10 @@ func createResultsCacheMatrixedTaskRuns(rpt *ResolvedPipelineTask) (resultsCache
 // ValidateParamEnumSubset finds the referenced pipeline-level params in the resolved pipelineTask.
 // It then validates if the referenced pipeline-level param enums are subsets of the resolved pipelineTask-level param enums
 func ValidateParamEnumSubset(pipelineTaskParams []v1.Param, pipelineParamSpecs []v1.ParamSpec, rt *resources.ResolvedTask) error {
+	// When the matrix Task has no TaskRun, the rt will be nil, we should skip the validation.
+	if rt == nil {
+		return nil
+	}
 	for _, p := range pipelineTaskParams {
 		// calculate referenced param enums
 		res, present, errString := substitution.ExtractVariablesFromString(p.Value.StringVal, "params")


Test patch:
diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
index fe6deee7c78..4c36927ebed 100644
--- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
+++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
@@ -5236,6 +5236,29 @@ func TestValidateParamEnumSubset_Valid(t *testing.T) {
 					},
 				},
 			},
+		}, {
+			name: "rt is nil - pass",
+			params: []v1.Param{
+				{
+					Name: "resolved-task-p1",
+					Value: v1.ParamValue{
+						StringVal: "$(params.p1) and $(params.p2)",
+					},
+				},
+			},
+			pipelinePs: []v1.ParamSpec{
+				{
+					Name: "p1",
+					Type: v1.ParamTypeString,
+					Enum: []string{"v1", "v2"},
+				},
+				{
+					Name: "p2",
+					Type: v1.ParamTypeString,
+					Enum: []string{"v3", "v4"},
+				},
+			},
+			rt: nil,
 		},
 	}
 
@@ -5320,6 +5343,7 @@ func TestValidateParamEnumSubset_Invalid(t *testing.T) {
 				},
 			},
 		},
+		rt:      &resources.ResolvedTask{},
 		wantErr: errors.New("unexpected error in ExtractVariablesFromString: Invalid referencing of parameters in \"$(params.p1.aaa.bbb)\"! Only two dot-separated components after the prefix \"params\" are allowed."),
 	}}