Skip to content

Commit

Permalink
fix ValidateStepResultsVariables and validateTaskResultsVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhelil committed Sep 16, 2024
1 parent cd8a41e commit 8e0fa48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,12 +643,13 @@ func validateTaskContextVariables(ctx context.Context, steps []Step) *apis.Field

// validateTaskResultsVariables validates if the results referenced in step script are defined in task results
func validateTaskResultsVariables(ctx context.Context, steps []Step, results []TaskResult) (errs *apis.FieldError) {
resultsNames := sets.NewString()
taskResultNames := sets.NewString()
for _, r := range results {
resultsNames.Insert(r.Name)
taskResultNames.Insert(r.Name)
}

for idx, step := range steps {
errs = errs.Also(substitution.ValidateNoReferencesToUnknownVariables(step.Script, "results", resultsNames).ViaField("script").ViaFieldIndex("steps", idx))
errs = errs.Also(substitution.ValidateNoReferencesToUnknownVariables(step.Script, "results", taskResultNames).ViaField("script").ViaFieldIndex("steps", idx))
}
return errs
}
Expand Down Expand Up @@ -859,6 +860,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
}
2 changes: 1 addition & 1 deletion pkg/substitution/substitution.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func ValidateNoReferencesToUnknownVariables(value, prefix string, vars sets.Stri
v = TrimArrayIndex(v)
if !vars.Has(v) {
return &apis.FieldError{
Message: fmt.Sprintf("non-existent variable in %q", value),
Message: fmt.Sprintf("non-existent variable %s in %q", v, value),
// Empty path is required to make the `ViaField`, … work
Paths: []string{""},
}
Expand Down

0 comments on commit 8e0fa48

Please sign in to comment.