Skip to content

Commit d89850f

Browse files
Yongxuanzhangtekton-robot
authored andcommitted
don't validate skipped task results for pipeline results
This commit skip the validation for skipped task results in pipeline results. This fixes #6139. The skipped task results are not emitted by design thus we shouldn't validate if they are emitted. Pipeline results referenced to skipped task will not be emitted.
1 parent 9ff4f88 commit d89850f

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

docs/pipelines.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ tasks:
316316
value: https://github.com/tektoncd/catalog.git
317317
- name: revision
318318
# value can use params declared at the pipeline level or a static value like main
319-
value: $(params.gitRevision)
319+
value: $(params.gitRevision)
320320
- name: pathInRepo
321321
value: task/golang-build/0.3/golang-build.yaml
322322
```
@@ -1059,6 +1059,7 @@ This will cause an `InvalidTaskResultReference` validation error during `Pipelin
10591059

10601060
**Note:** Since a `Pipeline Result` can contain references to multiple `Task Results`, if any of those
10611061
`Task Result` references are invalid the entire `Pipeline Result` is not emitted.
1062+
**Note:** If a `PipelineTask` referenced by the `Pipeline Result` was skipped, the `Pipeline Result` will not be emitted and the `PipelineRun` will not fail due to a missing result.
10621063

10631064
## Configuring the `Task` execution order
10641065

@@ -1302,7 +1303,7 @@ results:
13021303
value: $(finally.check-count.results.comment-count-validate)
13031304
finally:
13041305
- name: check-count
1305-
taskRef:
1306+
taskRef:
13061307
name: example-task-name
13071308
```
13081309

@@ -1790,7 +1791,7 @@ Consult the documentation of the custom task that you are using to determine whe
17901791
Pipelines do not support the following items with custom tasks:
17911792
* Pipeline Resources
17921793

1793-
### Known Custom Tasks
1794+
### Known Custom Tasks
17941795

17951796
We try to list as many known Custom Tasks as possible here so that users can easily find what they want. Please feel free to share the Custom Task you implemented in this table.
17961797

pkg/reconciler/pipelinerun/pipelinerun.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1beta1.PipelineRun, get
686686

687687
pr.Status.SkippedTasks = pipelineRunFacts.GetSkippedTasks()
688688
if after.Status == corev1.ConditionTrue || after.Status == corev1.ConditionFalse {
689-
pr.Status.PipelineResults, err = resources.ApplyTaskResultsToPipelineResults(pipelineSpec.Results,
690-
pipelineRunFacts.State.GetTaskRunsResults(), pipelineRunFacts.State.GetRunsResults())
689+
pr.Status.PipelineResults, err = resources.ApplyTaskResultsToPipelineResults(ctx, pipelineSpec.Results,
690+
pipelineRunFacts.State.GetTaskRunsResults(), pipelineRunFacts.State.GetRunsResults(), pr.Status.SkippedTasks)
691691
if err != nil {
692692
pr.Status.MarkFailed(ReasonFailedValidation, err.Error())
693693
return err

pkg/reconciler/pipelinerun/resources/apply.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424

2525
"github.com/tektoncd/pipeline/pkg/apis/config"
26+
2627
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
2728
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
2829
"github.com/tektoncd/pipeline/pkg/substitution"
@@ -328,11 +329,18 @@ func replaceParamValues(params []v1beta1.Param, stringReplacements map[string]st
328329
// and omitted from the returned slice. A nil slice is returned if no results are passed in or all
329330
// results are invalid.
330331
func ApplyTaskResultsToPipelineResults(
332+
ctx context.Context,
331333
results []v1beta1.PipelineResult,
332334
taskRunResults map[string][]v1beta1.TaskRunResult,
333-
customTaskResults map[string][]v1beta1.CustomRunResult) ([]v1beta1.PipelineRunResult, error) {
335+
customTaskResults map[string][]v1beta1.CustomRunResult,
336+
skippedTasks []v1beta1.SkippedTask) ([]v1beta1.PipelineRunResult, error) {
334337
var runResults []v1beta1.PipelineRunResult
335338
var invalidPipelineResults []string
339+
skippedTaskNames := map[string]bool{}
340+
for _, t := range skippedTasks {
341+
skippedTaskNames[t.Name] = true
342+
}
343+
336344
stringReplacements := map[string]string{}
337345
arrayReplacements := map[string][]string{}
338346
objectReplacements := map[string]map[string]string{}
@@ -353,6 +361,11 @@ func ApplyTaskResultsToPipelineResults(
353361
continue
354362
}
355363
variableParts := strings.Split(variable, ".")
364+
// if the referenced task is skipped, we should also skip the results replacements
365+
if _, ok := skippedTaskNames[variableParts[1]]; ok {
366+
validPipelineResult = false
367+
continue
368+
}
356369
if (variableParts[0] != v1beta1.ResultTaskPart && variableParts[0] != v1beta1.ResultFinallyPart) || variableParts[2] != v1beta1.ResultResultPart {
357370
validPipelineResult = false
358371
invalidPipelineResults = append(invalidPipelineResults, pipelineResult.Name)

pkg/reconciler/pipelinerun/resources/apply_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,7 +3497,7 @@ func TestApplyFinallyResultsToPipelineResults(t *testing.T) {
34973497
},
34983498
} {
34993499
t.Run(tc.description, func(t *testing.T) {
3500-
received, _ := ApplyTaskResultsToPipelineResults(tc.results, tc.taskResults, tc.runResults)
3500+
received, _ := ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, nil /* skippedTasks */)
35013501
if d := cmp.Diff(tc.expected, received); d != "" {
35023502
t.Errorf(diff.PrintWantGot(d))
35033503
}
@@ -3511,6 +3511,7 @@ func TestApplyTaskResultsToPipelineResults(t *testing.T) {
35113511
results []v1beta1.PipelineResult
35123512
taskResults map[string][]v1beta1.TaskRunResult
35133513
runResults map[string][]v1beta1.CustomRunResult
3514+
skippedTasks []v1beta1.SkippedTask
35143515
expectedResults []v1beta1.PipelineRunResult
35153516
expectedError error
35163517
}{{
@@ -3965,9 +3966,28 @@ func TestApplyTaskResultsToPipelineResults(t *testing.T) {
39653966
Name: "pipeline-result-2",
39663967
Value: *v1beta1.NewStructuredValues("do, rae, mi, rae, do"),
39673968
}},
3969+
}, {
3970+
description: "multiple-results-skipped-and-normal-tasks",
3971+
results: []v1beta1.PipelineResult{{
3972+
Name: "pipeline-result-1",
3973+
Value: *v1beta1.NewStructuredValues("$(tasks.skippedTask.results.foo)"),
3974+
}, {
3975+
Name: "pipeline-result-2",
3976+
Value: *v1beta1.NewStructuredValues("$(tasks.skippedTask.results.foo), $(tasks.normaltask.results.baz)"),
3977+
}},
3978+
taskResults: map[string][]v1beta1.TaskRunResult{
3979+
"normaltask": {{
3980+
Name: "baz",
3981+
Value: *v1beta1.NewStructuredValues("rae"),
3982+
}},
3983+
},
3984+
skippedTasks: []v1beta1.SkippedTask{{
3985+
Name: "skippedTask",
3986+
}},
3987+
expectedResults: nil,
39683988
}} {
39693989
t.Run(tc.description, func(t *testing.T) {
3970-
received, err := ApplyTaskResultsToPipelineResults(tc.results, tc.taskResults, tc.runResults)
3990+
received, err := ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, tc.skippedTasks)
39713991
if tc.expectedError != nil {
39723992
if d := cmp.Diff(tc.expectedError.Error(), err.Error()); d != "" {
39733993
t.Errorf("ApplyTaskResultsToPipelineResults() errors diff %s", diff.PrintWantGot(d))

0 commit comments

Comments
 (0)