Skip to content

Commit

Permalink
Validation for invalid Task Result expressions in Pipeline Result
Browse files Browse the repository at this point in the history
Prior to this commit, the validation for invalid `Task Result` expressions
in `Pipeline` `Result`'s was not extensive.

This commit adds the case where a `Pipeline` would be invalid if there is
no expression following the valid form `$(tasks,<task-name>.results.<result-name>)`.

Please reference this [doc](https://github.com/tektoncd/pipeline/blob/main/docs/pipelines.md#emitting-results-from-a-pipeline) for more information.

Fixes bug [tektoncd#4922](tektoncd#4922)

/kind bug
/cc @jerop
  • Loading branch information
Varun Singhai committed Jun 9, 2022
1 parent 4621a66 commit 0787f53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func validatePipelineResults(results []PipelineResult) (errs *apis.FieldError) {
if !ok {
errs = errs.Also(apis.ErrInvalidValue("expected pipeline results to be task result expressions but no expressions were found",
"value").ViaFieldIndex("results", idx))
break
}

if LooksLikeContainsResultRefs(expressions) {
Expand All @@ -264,6 +265,9 @@ func validatePipelineResults(results []PipelineResult) (errs *apis.FieldError) {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("expected all of the expressions %v to be result expressions but only %v were", expressions, resultRefs),
"value").ViaFieldIndex("results", idx))
}
} else {
errs = errs.Also(apis.ErrInvalidValue("expected pipeline results to be task result expressions but an invalid expressions was found",
"value").ViaFieldIndex("results", idx))
}

}
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,17 @@ func TestValidatePipelineResults_Failure(t *testing.T) {
Message: `invalid value: expected pipeline results to be task result expressions but no expressions were found`,
Paths: []string{"results[0].value"},
},
}, {
desc: "invalid pipeline result value with invalid expression",
results: []PipelineResult{{
Name: "my-pipeline-result",
Description: "this is my pipeline result",
Value: "$(foo.bar)",
}},
expectedError: apis.FieldError{
Message: `invalid value: expected pipeline results to be task result expressions but an invalid expressions was found`,
Paths: []string{"results[0].value"},
},
}}
for _, tt := range tests {
err := validatePipelineResults(tt.results)
Expand Down

0 comments on commit 0787f53

Please sign in to comment.