mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-30 07:18:44 +00:00
* Moved CommandContext and CommandResult to models (#193) * Moved CommandContext and CommandResult to models * move from models to command rename CommandContext -> Context rename CommandResult -> Result * moved command related helpers into command package * move ProjectCommandContext and ProjectResult to command/project package * move project command context and project result * revert unrelated code * move tests * fix left over * fix linting * fix tests * remove unused import * fix project context dependencies * fix depenedecies * fix typo
28 lines
921 B
Go
28 lines
921 B
Go
package runtime
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/runatlantis/atlantis/server/events/command"
|
|
)
|
|
|
|
// EnvStepRunner set environment variables.
|
|
type EnvStepRunner struct {
|
|
RunStepRunner *RunStepRunner
|
|
}
|
|
|
|
// Run runs the env step command.
|
|
// value is the value for the environment variable. If set this is returned as
|
|
// the value. Otherwise command is run and its output is the value returned.
|
|
func (r *EnvStepRunner) Run(ctx command.ProjectContext, command string, value string, path string, envs map[string]string) (string, error) {
|
|
if value != "" {
|
|
return value, nil
|
|
}
|
|
res, err := r.RunStepRunner.Run(ctx, command, path, envs)
|
|
// Trim newline from res to support running `echo env_value` which has
|
|
// a newline. We don't recommend users run echo -n env_value to remove the
|
|
// newline because -n doesn't work in the sh shell which is what we use
|
|
// to run commands.
|
|
return strings.TrimSuffix(res, "\n"), err
|
|
}
|