From 5c99d1c2a42d2142522e9833f5c21f1977d369d8 Mon Sep 17 00:00:00 2001 From: Maxime Deravet Date: Thu, 13 Jun 2019 12:54:34 -0700 Subject: [PATCH] Expand $PATH --- server/events/runtime/run_step_runner.go | 3 ++- server/events/runtime/run_step_runner_test.go | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) 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) {