Skip to content

Commit

Permalink
WIP expose env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ZIJ authored and motatoes committed Jan 10, 2024
1 parent 045cd0d commit 04dd335
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cli/pkg/core/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 7 additions & 1 deletion cli/pkg/core/runners/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cli/pkg/digger/digger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 04dd335

Please sign in to comment.