mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-03 19:18:47 +00:00
* MultiEnv step added * Values removed from the output * Fixing tests * multienv_step_runner_test added * Documentation of new feature added * Documentatation of new feature modified * multienv_step test file extension changed * Fixed multinev_step_runner test * Enhanced debug logging in multienv_step_runner * Enhanced errorhandling * Test command modified * Test command modified * Test command modified * Test command modified * Errorhandling modified * Test command modified * Test command modified * Create empty map in test * Fixing test ExpOut * Testing, refactoring, eliminating extra debug log * MultiEnv result modified from json to plain string * MultiEnv step Run parameter updated * Import added * project_command_runner updated * project_command_runner updated * multienv_step_runner_test updated * multienv doc modified * Update runatlantis.io/docs/custom-workflows.md Co-authored-by: PePe Amengual <jose.amengual@gmail.com> Co-authored-by: Istvan Tapaszto <istvan.tapaszto@msci.com> Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
40 lines
1.1 KiB
Go
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)
|
|
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
|
|
}
|