Skip to content

Commit

Permalink
Use parseMultienvLine for parsing multienv steps output
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro López (inkel) <leandro.lopez@grafana.com>
  • Loading branch information
inkel committed Jun 26, 2023
1 parent 7d06bdd commit 41cde2a
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions server/core/runtime/multienv_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ func (r *MultiEnvStepRunner) Run(ctx command.ProjectContext, command string, pat
var sb strings.Builder
sb.WriteString("Dynamic environment variables added:\n")

envVars := strings.Split(res, ",")
for _, item := range envVars {
// Only split after the first = found in case the environment variable value has
// = in it (as might be the case with access tokens)
nameValue := strings.SplitN(strings.TrimRight(item, "\n"), "=", 2)
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)
}
vars, err := parseMultienvLine(res)
if err != nil {
return "", fmt.Errorf("Invalid environment variable definition: %s (%w)", res, err)
}

for i := 0; i < len(vars); i += 2 {
key := vars[i]
envs[key] = vars[i+1]
sb.WriteString(key)
sb.WriteRune('\n')
}

return sb.String(), nil
}

Expand Down

0 comments on commit 41cde2a

Please sign in to comment.