diff --git a/cli/pkg/core/execution/execution.go b/cli/pkg/core/execution/execution.go index c6c90fd3a..a9b8c88ae 100644 --- a/cli/pkg/core/execution/execution.go +++ b/cli/pkg/core/execution/execution.go @@ -92,6 +92,7 @@ type DiggerExecutor struct { ProjectPath string StateEnvVars map[string]string CommandEnvVars map[string]string + RunEnvVars map[string]string ApplyStage *orchestrator.Stage PlanStage *orchestrator.Stage CommandRunner runners.CommandRun @@ -208,7 +209,7 @@ func (d DiggerExecutor) Plan() (bool, bool, string, string, error) { } commands = append(commands, step.Value) log.Printf("Running %v for **%v**\n", step.Value, d.ProjectNamespace+"#"+d.ProjectName) - _, _, err := d.CommandRunner.Run(d.ProjectPath, step.Shell, commands) + _, _, err := d.CommandRunner.Run(d.ProjectPath, step.Shell, commands, d.RunEnvVars) if err != nil { return false, false, "", "", fmt.Errorf("error running command: %v", err) } diff --git a/cli/pkg/core/runners/runners.go b/cli/pkg/core/runners/runners.go index 9a13e9127..aaa5be6da 100644 --- a/cli/pkg/core/runners/runners.go +++ b/cli/pkg/core/runners/runners.go @@ -16,7 +16,7 @@ type CommandRun interface { type CommandRunner struct { } -func (c CommandRunner) Run(workingDir string, shell string, commands []string) (string, string, error) { +func (c CommandRunner) Run(workingDir string, shell string, commands []string, envs map[string]string) (string, string, error) { var args []string if shell == "" { shell = "bash" @@ -40,6 +40,12 @@ func (c CommandRunner) Run(workingDir string, shell string, commands []string) ( cmd := exec.Command(shell, args...) cmd.Dir = workingDir + env := os.Environ() + for k, v := range envs { + env = append(env, fmt.Sprintf("%s=%s", k, v)) + } + cmd.Env = env + var stdout, stderr bytes.Buffer mwout := io.MultiWriter(os.Stdout, &stdout) mwerr := io.MultiWriter(os.Stderr, &stderr) diff --git a/cli/pkg/digger/digger.go b/cli/pkg/digger/digger.go index c35e3a022..54631b972 100644 --- a/cli/pkg/digger/digger.go +++ b/cli/pkg/digger/digger.go @@ -196,6 +196,7 @@ func run(command string, job orchestrator.Job, policyChecker policy.Checker, org ProjectName: job.ProjectName, ProjectPath: projectPath, StateEnvVars: job.StateEnvVars, + RunEnvVars: job.RunEnvVars, CommandEnvVars: job.CommandEnvVars, ApplyStage: job.ApplyStage, PlanStage: job.PlanStage, @@ -509,6 +510,7 @@ func RunJob( ProjectName: job.ProjectName, ProjectPath: projectPath, StateEnvVars: job.StateEnvVars, + RunEnvVars: job.RunEnvVars, CommandEnvVars: job.CommandEnvVars, ApplyStage: job.ApplyStage, PlanStage: job.PlanStage,