From 5280efc4205866acd0ba701b44c4ac52d6f65751 Mon Sep 17 00:00:00 2001 From: Joao Pedro Silva Date: Wed, 13 Dec 2023 15:01:11 +0000 Subject: [PATCH] FIX: Prevent panic on parameter evaluation Signed-off-by: Joao Pedro Silva --- pkg/reconciler/pipelinerun/pipelinerun_test.go | 4 ++++ pkg/reconciler/pipelinerun/resources/apply.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 55b048c22ba..28e001515eb 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -296,6 +296,8 @@ spec: value: $(context.pipeline.name) - name: contextRetriesParam value: $(context.pipelineTask.retries) + - name: param-not-found + value: $(params.notfound) retries: 5 taskRef: name: unit-test-task @@ -385,6 +387,8 @@ spec: value: test-pipeline - name: contextRetriesParam value: "5" + - name: param-not-found + value: $(params.notfound) retries: 5 serviceAccountName: test-sa taskRef: diff --git a/pkg/reconciler/pipelinerun/resources/apply.go b/pkg/reconciler/pipelinerun/resources/apply.go index 5ed091dd11f..00ce401dc88 100644 --- a/pkg/reconciler/pipelinerun/resources/apply.go +++ b/pkg/reconciler/pipelinerun/resources/apply.go @@ -160,7 +160,7 @@ func filterMatrixContextVar(params v1.Params) v1.Params { // tasks..matrix.length // tasks..matrix..length subExpressions := strings.Split(expression, ".") - if subExpressions[2] == "matrix" && subExpressions[len(subExpressions)-1] == "length" { + if len(subExpressions) >= 4 && subExpressions[2] == "matrix" && subExpressions[len(subExpressions)-1] == "length" { filteredParams = append(filteredParams, param) } }