Files
atlantis/server/core/runtime/multienv_step_runner.go
Aiden Scandella ff1094fa04 feat: stream output for custom workflows (#2261)
* Start threading job output to RunStepRunner

* Strip ANSI

* Fix lint

* Use waitgroup to avoid test flakiness

* Move waitgroup higher

* Add ANSI test and use strings.Builder

* Fix lint

* Use errors.Wrap per style guide

* Create ShellCommandRunner to encapsulate streaming

* WIP: shell command runner

* Update signatures to propagate error finding version

* Fix log output

* Fix error checking

* Fix accidental whitespace stripping

* Remove unused struct field

* Fix error checking in terraform client

* Add unit tests to verify command output handler was called

* Remove err from async interface

* Remove duplicative log now that shell command runner does it

* Hide output in stream for env/multienv

* Add comment explaining goroutines

* Use printf for better macOS compatibility
2022-06-22 09:29:41 -07:00

40 lines
1.1 KiB
Go

package runtime
import (
"fmt"
"strings"
"github.com/runatlantis/atlantis/server/events/command"
)
// EnvStepRunner set environment variables.
type MultiEnvStepRunner struct {
RunStepRunner *RunStepRunner
}
// Run runs the multienv step command.
// The command must return a json string containing the array of name-value pairs that are being added as extra environment variables
func (r *MultiEnvStepRunner) Run(ctx command.ProjectContext, command string, path string, envs map[string]string) (string, error) {
res, err := r.RunStepRunner.Run(ctx, command, path, envs, false)
if err == nil {
envVars := strings.Split(res, ",")
if len(envVars) > 0 {
var sb strings.Builder
sb.WriteString("Dynamic environment variables added:\n")
for _, item := range envVars {
nameValue := strings.Split(item, "=")
if len(nameValue) == 2 {
envs[nameValue[0]] = nameValue[1]
sb.WriteString(nameValue[0])
sb.WriteString("\n")
} else {
return "", fmt.Errorf("Invalid environment variable definition: %s", item)
}
}
return sb.String(), nil
}
return "No dynamic environment variable added", nil
}
return "", err
}