From 8204ef4b821213a667bd2bbe72fc7bdc3f516626 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Mon, 2 Nov 2020 13:56:20 -0800 Subject: [PATCH] Change handling of ExtraPath (#406) To make the handling of ExtraPath portable append it to the front of the PATH when it exists, instead of always changing the script. --- pkg/runner/step_context.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 13672df..9331067 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -92,6 +92,11 @@ func (sc *StepContext) setupEnv() common.Executor { env = mergeMaps(rc.GetEnv(), step.GetEnv()) } + if (rc.ExtraPath != nil) && (len(rc.ExtraPath) > 0) { + s := append(rc.ExtraPath, os.Getenv("PATH")) + env["PATH"] = strings.Join(s, string(os.PathSeparator)) + } + for k, v := range env { env[k] = rc.ExprEval.Interpolate(v) } @@ -106,11 +111,7 @@ func (sc *StepContext) setupShellCommand() common.Executor { step := sc.Step return func(ctx context.Context) error { var script strings.Builder - - _, err := script.WriteString(fmt.Sprintf("PATH=\"%s:${PATH}\"\n", strings.Join(rc.ExtraPath, ":"))) - if err != nil { - return err - } + var err error if step.WorkingDirectory == "" { step.WorkingDirectory = rc.Run.Job().Defaults.Run.WorkingDirectory