Skip to content

Commit

Permalink
fix ValidateStepResultsVariables to validate stepResults only
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhelil committed Oct 28, 2024
1 parent 96db451 commit 5a87c4a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
48 changes: 48 additions & 0 deletions examples/v1/taskruns/alpha/task-stepaction-results.yaml
Original file line number Diff line number Diff line change
@@ -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

1 change: 0 additions & 1 deletion pkg/apis/pipeline/v1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 0 additions & 13 deletions pkg/apis/pipeline/v1alpha1/stepaction_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
13 changes: 0 additions & 13 deletions pkg/apis/pipeline/v1beta1/stepaction_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 5a87c4a

Please sign in to comment.