Skip to content

Commit

Permalink
Merge pull request #1265 from jstrachan/improve-uses
Browse files Browse the repository at this point in the history
fix: add missing workspace bindings
  • Loading branch information
jenkins-x-bot-test authored Mar 25, 2021
2 parents e6c7a1a + cc0d888 commit 7f021c3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/triggerconfig/inrepo/load_pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func processUsesSteps(resolver *UsesResolver, prs *tektonv1beta1.PipelineRun) er
loc := &UseLocation{
PipelineRunSpec: &prs.Spec,
PipelineSpec: prs.Spec.PipelineSpec,
PipelineTask: pt,
TaskName: pt.Name,
TaskSpec: ts,
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/triggerconfig/inrepo/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type UseLocation struct {
PipelineRunSpec *v1beta1.PipelineRunSpec
PipelineSpec *v1beta1.PipelineSpec
PipelineTask *v1beta1.PipelineTask
TaskName string
TaskRunSpec *v1beta1.TaskRunSpec
TaskSpec *v1beta1.TaskSpec
Expand All @@ -35,6 +36,10 @@ func UseParametersAndResults(ctx context.Context, loc *UseLocation, uses *v1beta
ps.Results = usePipelineResults(ps.Results, results)
ps.Workspaces = usePipelineWorkspaces(ps.Workspaces, uses.Workspaces)
}
pt := loc.PipelineTask
if pt != nil {
pt.Workspaces = useWorkspaceTaskBindings(pt.Workspaces, ToWorkspacePipelineTaskBindingsFromDeclarations(uses.Workspaces))
}
trs := loc.TaskRunSpec
if trs != nil {
trs.Params = useParameters(trs.Params, parameters)
Expand Down Expand Up @@ -206,6 +211,23 @@ func useResults(results []v1beta1.TaskResult, uses []v1beta1.TaskResult) []v1bet
return results
}

func useWorkspaceTaskBindings(ws []v1beta1.WorkspacePipelineTaskBinding, uses []v1beta1.WorkspacePipelineTaskBinding) []v1beta1.WorkspacePipelineTaskBinding {
for _, u := range uses {
found := false
for i := range ws {
param := &ws[i]
if param.Name == u.Name {
found = true
break
}
}
if !found {
ws = append(ws, u)
}
}
return ws
}

func usePipelineWorkspaces(ws []v1beta1.PipelineWorkspaceDeclaration, uses []v1beta1.WorkspaceDeclaration) []v1beta1.PipelineWorkspaceDeclaration {
for _, u := range uses {
found := false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ spec:
workspaces:
- description: The git repo will be cloned onto the volume backing this workspace
name: output
workspaces:
- name: output
workspace: output
workspaces:
- description: The git repo will be cloned onto the volume backing this workspace
name: output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ spec:
- description: The git repo will be cloned onto the volume backing this workspace
mountPath: /workspace
name: output
workspaces:
- name: output
workspace: output
workspaces:
- description: The git repo will be cloned onto the volume backing this workspace
name: output
Expand Down

0 comments on commit 7f021c3

Please sign in to comment.