Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in Pre or Post Workflow Hook Scripts do not Produce any Output #3421

Closed
X-Guardian opened this issue May 20, 2023 · 0 comments · Fixed by #3422
Closed

Errors in Pre or Post Workflow Hook Scripts do not Produce any Output #3421

X-Guardian opened this issue May 20, 2023 · 0 comments · Fixed by #3422
Labels
bug Something isn't working

Comments

@X-Guardian
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

If a pre or post workflow hook script errors with a non zero exit code, any output from the script is not logged.

Reproduction Steps

repos.yaml:

repos:
- id: /.*/
  pre_workflow_hooks:
    - run: echo "test line 1" && exit 0
    - run: echo "test line 2" && exit 1

Logs

Logs
{"level":"info","ts":"2023-05-20T12:06:43.863+0100","caller":"runtime/pre_workflow_hook_runner.go:77","msg":"successfully ran \"echo \\\"test line 1\\\" && exit 0\" in \"atlantis-test\\\\1\\\\default\"","json":{"repo":"X-Guardian/atlantis-test","pull":"1"}}
{"level":"error","ts":"2023-05-20T12:06:44.831+0100","caller":"events/command_runner.go:293","msg":"Error running pre-workflow hooks exit status 1: running \"echo \\\"test line 2\\\" && exit 1\" in \"atlantis-test\\\\1\\\\default\": \ntest line 2\n. Proceeding with plan command.","json":{"repo":"X-Guardian/atlantis-test","pull":"1"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\tC:/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/command_runner.go:293"}

Output Screenshot

image

Environment details

  • Atlantis version: 0.23.5
  • Deployment method: local
  • If not running the latest Atlantis version have you tried to reproduce this issue on the latest version: n/a
  • Atlantis flags: none
  • Atlantis server-side config file: none

Additional Context

  • The OutputHandler.SendWorkFlowHook calls in these functions should be before the error handling blocks:
    • out, err := cmd.CombinedOutput()
      if err != nil {
      err = fmt.Errorf("%s: running %q in %q: \n%s", err, command, path, out)
      ctx.Log.Debug("error: %s", err)
      return "", "", err
      }
      // Read the value from the "outputFilePath" file
      // to be returned as a custom description.
      var customStatusOut []byte
      if _, err := os.Stat(outputFilePath); err == nil {
      var customStatusErr error
      customStatusOut, customStatusErr = os.ReadFile(outputFilePath)
      if customStatusErr != nil {
      err = fmt.Errorf("%s: running %q in %q: \n%s", err, command, path, out)
      ctx.Log.Debug("error: %s", err)
      return "", "", err
      }
      }
      wh.OutputHandler.SendWorkflowHook(ctx, string(out), false)
      wh.OutputHandler.SendWorkflowHook(ctx, "\n", true)
    • out, err := cmd.CombinedOutput()
      if err != nil {
      err = fmt.Errorf("%s: running %q in %q: \n%s", err, command, path, out)
      ctx.Log.Debug("error: %s", err)
      return "", "", err
      }
      // Read the value from the "outputFilePath" file
      // to be returned as a custom description.
      var customStatusOut []byte
      if _, err := os.Stat(outputFilePath); err == nil {
      var customStatusErr error
      customStatusOut, customStatusErr = os.ReadFile(outputFilePath)
      if customStatusErr != nil {
      err = fmt.Errorf("%s: running %q in %q: \n%s", err, command, path, out)
      ctx.Log.Debug("error: %s", err)
      return "", "", err
      }
      }
      wh.OutputHandler.SendWorkflowHook(ctx, string(out), false)
      wh.OutputHandler.SendWorkflowHook(ctx, "\n", true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant