Skip to content

Commit

Permalink
Refactor Task Results Substitution
Browse files Browse the repository at this point in the history
While working on When Expressions, found that this refactor would make
it easier to extend Task Results Substitution to When Expressions.
Specifically moving the logic to get the results refs to resultrefresolution.go
and splitting the logic to two functions with separate concerns.
  • Loading branch information
jerop authored and tekton-robot committed Sep 4, 2020
1 parent cac869c commit bf4d14d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 1 addition & 7 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ func ApplyContexts(spec *v1beta1.PipelineSpec, pipelineName string, pr *v1beta1.

// ApplyTaskResults applies the ResolvedResultRef to each PipelineTask.Params in targets
func ApplyTaskResults(targets PipelineRunState, resolvedResultRefs ResolvedResultRefs) {
stringReplacements := map[string]string{}

for _, resolvedResultRef := range resolvedResultRefs {
replaceTarget := fmt.Sprintf("%s.%s.%s.%s", v1beta1.ResultTaskPart, resolvedResultRef.ResultReference.PipelineTask, v1beta1.ResultResultPart, resolvedResultRef.ResultReference.Result)
stringReplacements[replaceTarget] = resolvedResultRef.Value.StringVal
}

stringReplacements := resolvedResultRefs.getStringReplacements()
for _, resolvedPipelineRunTask := range targets {
// also make substitution for resolved condition checks
for _, resolvedConditionCheck := range resolvedPipelineRunTask.ResolvedConditionChecks {
Expand Down
13 changes: 13 additions & 0 deletions pkg/reconciler/pipelinerun/resources/resultrefresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,16 @@ func findTaskResultForParam(taskRun *v1beta1.TaskRun, reference *v1beta1.ResultR
}
return nil, fmt.Errorf("Could not find result with name %s for task run %s", reference.Result, reference.PipelineTask)
}

func (rs ResolvedResultRefs) getStringReplacements() map[string]string {
replacements := map[string]string{}
for _, r := range rs {
replaceTarget := r.getReplaceTarget()
replacements[replaceTarget] = r.Value.StringVal
}
return replacements
}

func (r *ResolvedResultRef) getReplaceTarget() string {
return fmt.Sprintf("%s.%s.%s.%s", v1beta1.ResultTaskPart, r.ResultReference.PipelineTask, v1beta1.ResultResultPart, r.ResultReference.Result)
}

0 comments on commit bf4d14d

Please sign in to comment.