diff --git a/pkg/workspace/apply.go b/pkg/workspace/apply.go index 776888debee..71f3349e594 100644 --- a/pkg/workspace/apply.go +++ b/pkg/workspace/apply.go @@ -225,6 +225,10 @@ func findWorkspaceSubstitutionLocationsInSidecars(sidecars []v1.Sidecar) sets.St for i := range sidecar.Command { locationsToCheck.Insert(sidecar.Command[i]) } + locationsToCheck.Insert(sidecar.WorkingDir) + for _, e := range sidecar.Env { + locationsToCheck.Insert(e.Value) + } } return locationsToCheck } @@ -241,6 +245,11 @@ func findWorkspaceSubstitutionLocationsInSteps(steps []v1.Step) sets.String { for i := range step.Command { locationsToCheck.Insert(step.Command[i]) } + + locationsToCheck.Insert(step.WorkingDir) + for _, e := range step.Env { + locationsToCheck.Insert(e.Value) + } } return locationsToCheck } @@ -255,6 +264,11 @@ func findWorkspaceSubstitutionLocationsInStepTemplate(stepTemplate *v1.StepTempl for i := range stepTemplate.Command { locationsToCheck.Insert(stepTemplate.Command[i]) } + + locationsToCheck.Insert(stepTemplate.WorkingDir) + for _, e := range stepTemplate.Env { + locationsToCheck.Insert(e.Value) + } } return locationsToCheck } diff --git a/pkg/workspace/apply_test.go b/pkg/workspace/apply_test.go index 7c0528d872c..6b5956e40c9 100644 --- a/pkg/workspace/apply_test.go +++ b/pkg/workspace/apply_test.go @@ -1225,6 +1225,87 @@ func TestFindWorkspacesUsedByTask(t *testing.T) { "steptemplate-args", "steptemplate-command", ), + }, { + name: "workspace used in step env", + ts: &v1.TaskSpec{ + Steps: []v1.Step{{ + Name: "step-name", + Image: "step-image", + Env: []corev1.EnvVar{{ + Name: "path", + Value: "$(workspaces.env-ws.path)", + }}, + Command: []string{"ls"}, + }}, + }, + want: sets.NewString( + "env-ws", + ), + }, { + name: "workspace used in step workingDir", + ts: &v1.TaskSpec{ + Steps: []v1.Step{{ + Name: "step-name", + Image: "step-image", + WorkingDir: "$(workspaces.shared.path)", + Command: []string{"ls"}, + }}, + }, + want: sets.NewString( + "shared", + ), + }, { + name: "workspace used in sidecar env", + ts: &v1.TaskSpec{ + Sidecars: []v1.Sidecar{{ + Name: "step-name", + Image: "step-image", + Env: []corev1.EnvVar{{ + Name: "path", + Value: "$(workspaces.env-ws.path)", + }}, + Command: []string{"ls"}, + }}, + }, + want: sets.NewString( + "env-ws", + ), + }, { + name: "workspace used in sidecar workingDir", + ts: &v1.TaskSpec{ + Sidecars: []v1.Sidecar{{ + Name: "step-name", + Image: "step-image", + WorkingDir: "$(workspaces.shared.path)", + Command: []string{"ls"}, + }}, + }, + want: sets.NewString( + "shared", + ), + }, { + name: "workspace used in stepTemplate env", + ts: &v1.TaskSpec{ + StepTemplate: &v1.StepTemplate{ + Env: []corev1.EnvVar{{ + Name: "path", + Value: "$(workspaces.env-ws.path)", + }}, + }, + }, + want: sets.NewString( + "env-ws", + ), + }, { + name: "workspace used in stepTemplate workingDir", + ts: &v1.TaskSpec{ + StepTemplate: &v1.StepTemplate{ + WorkingDir: "$(workspaces.shared.path)", + }, + }, + want: sets.NewString( + "shared", + ), }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {