From 00856f15a7dd3c5dd0fe6318612fa8d2b3ae170c Mon Sep 17 00:00:00 2001 From: Simon Dahlbacka Date: Fri, 11 Oct 2024 17:59:02 +0300 Subject: [PATCH] feature: pass ot_ args to shellAfterCompleted (#420) * feature: pass ot_ args to shellAfterCompleted * refactor: Implement this the right way --------- Co-authored-by: James Read --- internal/executor/executor.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 12332af..aa5e758 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -454,10 +454,10 @@ func (ost *OutputStreamer) String() string { return ost.output.String() } -func buildEnv(req *ExecutionRequest) []string { +func buildEnv(args map[string]string) []string { ret := append(os.Environ(), "OLIVETIN=1") - for k, v := range req.Arguments { + for k, v := range args { varName := fmt.Sprintf("%v", strings.TrimSpace(strings.ToUpper(k))) // Skip arguments that might not have a name (eg, confirmation), as this causes weird bugs on Windows. @@ -480,7 +480,7 @@ func stepExec(req *ExecutionRequest) bool { cmd := wrapCommandInShell(ctx, req.finalParsedCommand) cmd.Stdout = streamer cmd.Stderr = streamer - cmd.Env = buildEnv(req) + cmd.Env = buildEnv(req.Arguments) req.logEntry.ExecutionStarted = true @@ -524,8 +524,10 @@ func stepExecAfter(req *ExecutionRequest) bool { var stderr bytes.Buffer args := map[string]string{ - "output": req.logEntry.Output, - "exitCode": fmt.Sprintf("%v", req.logEntry.ExitCode), + "output": req.logEntry.Output, + "exitCode": fmt.Sprintf("%v", req.logEntry.ExitCode), + "ot_executionTrackingId": req.TrackingID, + "ot_username": req.AuthenticatedUser.Username, } finalParsedCommand, _, err := parseCommandForReplacements(req.Action.ShellAfterCompleted, args) @@ -541,6 +543,8 @@ func stepExecAfter(req *ExecutionRequest) bool { cmd.Stdout = &stdout cmd.Stderr = &stderr + cmd.Env = buildEnv(args) + runerr := cmd.Start() waiterr := cmd.Wait()