diff --git a/examples/v1/taskruns/alpha/task-stepaction-results.yaml b/examples/v1/taskruns/alpha/task-stepaction-results.yaml new file mode 100644 index 00000000000..e3b91f271e1 --- /dev/null +++ b/examples/v1/taskruns/alpha/task-stepaction-results.yaml @@ -0,0 +1,48 @@ +apiVersion: tekton.dev/v1alpha1 +kind: StepAction +metadata: + name: step-action +spec: + params: + - name: message + type: string + env: + - name: message + value: $(params.message) + image: mirror.gcr.io/bash + script: | + #!/usr/bin/env bash + echo ${message} + +--- +apiVersion: tekton.dev/v1 +kind: TaskRun +metadata: + generateName: reference-step-result-in-step- +spec: + taskSpec: + description: | + A simple task to demonstrate how to reference a step result in another step when used alongside with task result + results: + - name: resultsDir + type: string + steps: + - name: collect + image: mirror.gcr.io/bash + results: + - name: message + type: string + script: | + #!/usr/bin/env sh + set -x + message="scott" + + echo -n "${message}" > $(step.results.message.path) + echo -n "tom" > $(results.resultsDir.path) + - name: reduce + params: + - name: message + value: $(steps.collect.results.message) + ref: + name: step-action + diff --git a/pkg/apis/pipeline/v1/task_validation.go b/pkg/apis/pipeline/v1/task_validation.go index 4232d295d2b..d93fce54940 100644 --- a/pkg/apis/pipeline/v1/task_validation.go +++ b/pkg/apis/pipeline/v1/task_validation.go @@ -859,6 +859,5 @@ func ValidateStepResultsVariables(ctx context.Context, results []StepResult, scr resultsNames.Insert(r.Name) } errs = errs.Also(substitution.ValidateNoReferencesToUnknownVariables(script, "step.results", resultsNames).ViaField("script")) - errs = errs.Also(substitution.ValidateNoReferencesToUnknownVariables(script, "results", resultsNames).ViaField("script")) return errs } diff --git a/pkg/apis/pipeline/v1alpha1/stepaction_validation_test.go b/pkg/apis/pipeline/v1alpha1/stepaction_validation_test.go index e1b3c0f3b8d..ee79af415a6 100644 --- a/pkg/apis/pipeline/v1alpha1/stepaction_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/stepaction_validation_test.go @@ -613,19 +613,6 @@ func TestStepActionSpecValidateError(t *testing.T) { Message: `windows script support requires "enable-api-fields" feature gate to be "alpha" but it is "beta"`, Paths: []string{}, }, - }, { - name: "step script refers to nonexistent result", - fields: fields{ - Image: "my-image", - Script: ` - #!/usr/bin/env bash - date | tee $(results.non-exist.path)`, - Results: []v1.StepResult{{Name: "a-result"}}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "\n\t\t\t#!/usr/bin/env bash\n\t\t\tdate | tee $(results.non-exist.path)"`, - Paths: []string{"script"}, - }, }, { name: "step script refers to nonexistent stepresult", fields: fields{ diff --git a/pkg/apis/pipeline/v1beta1/stepaction_validation_test.go b/pkg/apis/pipeline/v1beta1/stepaction_validation_test.go index 49efacdf91a..028fd7c2030 100644 --- a/pkg/apis/pipeline/v1beta1/stepaction_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/stepaction_validation_test.go @@ -613,19 +613,6 @@ func TestStepActionSpecValidateError(t *testing.T) { Message: `windows script support requires "enable-api-fields" feature gate to be "alpha" but it is "beta"`, Paths: []string{}, }, - }, { - name: "step script refers to nonexistent result", - fields: fields{ - Image: "my-image", - Script: ` - #!/usr/bin/env bash - date | tee $(results.non-exist.path)`, - Results: []v1.StepResult{{Name: "a-result"}}, - }, - expectedError: apis.FieldError{ - Message: `non-existent variable in "\n\t\t\t#!/usr/bin/env bash\n\t\t\tdate | tee $(results.non-exist.path)"`, - Paths: []string{"script"}, - }, }, { name: "step script refers to nonexistent stepresult", fields: fields{