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 0a41159e705..a0f8180f770 100644
--- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
+++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go
@@ -886,6 +886,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 b3696527310..9f93efe5456 100644
--- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
+++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go
@@ -5446,6 +5446,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,
 		},
 	}
 
@@ -5530,6 +5553,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."),
 	}}