diff --git a/server/events/runtime/run_step_runner.go b/server/events/runtime/run_step_runner.go index 6a2f859847..e0a39351ce 100644 --- a/server/events/runtime/run_step_runner.go +++ b/server/events/runtime/run_step_runner.go @@ -33,7 +33,7 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command string, pa "HEAD_BRANCH_NAME": ctx.Pull.HeadBranch, "HEAD_REPO_NAME": ctx.HeadRepo.Name, "HEAD_REPO_OWNER": ctx.HeadRepo.Owner, - "PATH": fmt.Sprintf("$PATH:%s", r.TerraformBinDir), + "PATH": fmt.Sprintf(os.ExpandEnv("$PATH:%s"), r.TerraformBinDir), "PLANFILE": filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectName)), "PROJECT_NAME": ctx.ProjectName, "PULL_AUTHOR": ctx.Pull.Author, @@ -46,6 +46,8 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command string, pa for key, val := range customEnvVars { finalEnvVars = append(finalEnvVars, fmt.Sprintf("%s=%s", key, val)) } + + cmd.Env = finalEnvVars out, err := cmd.CombinedOutput() diff --git a/server/events/runtime/run_step_runner_test.go b/server/events/runtime/run_step_runner_test.go index 54b3ef38e2..2d9bd97d5a 100644 --- a/server/events/runtime/run_step_runner_test.go +++ b/server/events/runtime/run_step_runner_test.go @@ -1,6 +1,8 @@ package runtime_test import ( + "fmt" + "os" "strings" "testing" @@ -64,7 +66,7 @@ func TestRunStepRunner_Run(t *testing.T) { ExpOut: "user_name=acme-user\n", },{ Command: "echo $PATH", - ExpOut: "$PATH:/bin/dir\n", + ExpOut: fmt.Sprintf(os.ExpandEnv("$PATH%s"),":/bin/dir\n"), }, }