From 4879e922c168f17ee08846c4ea12483414a17090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 4 Jul 2022 20:27:17 +0200 Subject: [PATCH] Avoid calling /bin/env in local backend (#1011) /bin/env was used to resolve a command name against PATH and pass additional environment variables. All of this can also be achieved using functionality already provided by go's exec lib, which will then internally pass the appropriate arguments to e.g. execve. --- pipeline/backend/local/local.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pipeline/backend/local/local.go b/pipeline/backend/local/local.go index 3afc8c0d9..6d254b7cd 100644 --- a/pipeline/backend/local/local.go +++ b/pipeline/backend/local/local.go @@ -49,16 +49,17 @@ func (e *local) Setup(ctx context.Context, proc *types.Config) error { // Exec the pipeline step. func (e *local) Exec(ctx context.Context, proc *types.Step) error { // Get environment variables - Command := []string{} + Env := os.Environ() for a, b := range proc.Environment { if a != "HOME" && a != "SHELL" { // Don't override $HOME and $SHELL - Command = append(Command, a+"="+b) + Env = append(Env, a+"="+b) } } + Command := []string{} if proc.Image == constant.DefaultCloneImage { // Default clone step - Command = append(Command, "CI_WORKSPACE="+e.workingdir+"/"+proc.Environment["CI_REPO"]) + Env = append(Env, "CI_WORKSPACE="+e.workingdir+"/"+proc.Environment["CI_REPO"]) Command = append(Command, "plugin-git") } else { // Use "image name" as run command @@ -72,7 +73,8 @@ func (e *local) Exec(ctx context.Context, proc *types.Step) error { } // Prepare command - e.cmd = exec.CommandContext(ctx, "/bin/env", Command...) + e.cmd = exec.CommandContext(ctx, Command[0], Command[1:]...) + e.cmd.Env = Env // Prepare working directory if proc.Image == constant.DefaultCloneImage {