diff --git a/server/events/runtime/run_step_runner.go b/server/events/runtime/run_step_runner.go index 6a2f859847..b41dc2635f 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,7 @@ 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..63fee17c75 100644 --- a/server/events/runtime/run_step_runner_test.go +++ b/server/events/runtime/run_step_runner_test.go @@ -1,10 +1,12 @@ package runtime_test import ( + "fmt" + "os" "strings" "testing" - version "github.com/hashicorp/go-version" + "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/runtime" "github.com/runatlantis/atlantis/server/logging" @@ -62,9 +64,9 @@ func TestRunStepRunner_Run(t *testing.T) { { Command: "echo user_name=$USER_NAME", ExpOut: "user_name=acme-user\n", - },{ + }, { Command: "echo $PATH", - ExpOut: "$PATH:/bin/dir\n", + ExpOut: fmt.Sprintf(os.ExpandEnv("$PATH%s"), ":/bin/dir\n"), }, } @@ -73,7 +75,7 @@ func TestRunStepRunner_Run(t *testing.T) { defaultVersion, _ := version.NewVersion("0.8") r := runtime.RunStepRunner{ DefaultTFVersion: defaultVersion, - TerraformBinDir: "/bin/dir", + TerraformBinDir: "/bin/dir", } for _, c := range cases { t.Run(c.Command, func(t *testing.T) {