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") 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."), }}