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

feat: Add A Server Config Flag to Enable Failure on Pre Workflow Hook Errors #3729

Merged
merged 4 commits into from Sep 1, 2023

Conversation

X-Guardian
Copy link
Contributor

@X-Guardian X-Guardian commented Sep 1, 2023

What

  • Add a fail-on-pre-workflow-hook-error flag to the Atlantis server configuration.
  • update the RunAutoplanCommand and RunCommentCommand functions to check the fail-on-pre-workflow-hook-error flag when pre workflow hooks fail, and if it is set, then do not run the requested Atlantis command.

Other Changes

  • Update the DefaultCommandRunner type user option property documentation.

Why

Closes #1834
Closes #2648

Tests

repos.yaml

repos:
- id: /.*/
  pre_workflow_hooks:
    - description: Hook1
      run: |
        exit 1

config.yaml

fail-on-pre-workflow-hook-error: true

Log Extract

{"level":"info","ts":"2023-09-01T16:55:09.711+0100","caller":"events/events_controller.go:550","msg":"parsed comment as command=\"plan\" verbose=false dir=\"\" workspace=\"\" project=\"\" policyset=\"\", clear-policy-approval=false, flags=\"\"","json":{"gh-request-id":"X-Github-Delivery=ecf0e060-48df-11ee-8e8e-d42179a4d4a2"}}
{"level":"error","ts":"2023-09-01T16:55:12.141+0100","caller":"events/command_runner.go:306","msg":"Error running pre-workflow hooks exit status 1: running \"sh -c exit 1\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\": \n.","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/command_runner.go:306"}
{"level":"error","ts":"2023-09-01T16:55:12.141+0100","caller":"events/command_runner.go:309","msg":"'fail-on-pre-workflow-hook-error' set, so not running plan command.","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/command_runner.go:309"}

config.yaml

fail-on-pre-workflow-hook-error: false

Log Extract

{"level":"info","ts":"2023-09-01T16:57:44.138+0100","caller":"events/events_controller.go:550","msg":"parsed comment as command=\"plan\" verbose=false dir=\"\" workspace=\"\" project=\"\" policyset=\"\", clear-policy-approval=false, flags=\"\"","json":{"gh-request-id":"X-Github-Delivery=4908c610-48e0-11ee-8cab-aa4635424ba1"}}
{"level":"error","ts":"2023-09-01T16:57:45.526+0100","caller":"events/command_runner.go:306","msg":"Error running pre-workflow hooks exit status 1: running \"sh -c exit 1\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\": \n.","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/command_runner.go:306"}
{"level":"error","ts":"2023-09-01T16:57:45.526+0100","caller":"events/command_runner.go:312","msg":"'fail-on-pre-workflow-hook-error' not set so running plan command.","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/command_runner.go:312"}

@X-Guardian X-Guardian requested a review from a team as a code owner September 1, 2023 16:02
@github-actions github-actions bot added docs Documentation go Pull requests that update Go code labels Sep 1, 2023
Copy link
Contributor

@jamengual jamengual left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @X-Guardian for your contribution...again

@jamengual jamengual merged commit dc64493 into runatlantis:main Sep 1, 2023
13 checks passed
@X-Guardian X-Guardian deleted the FailOnPreWorkflowHookError branch September 2, 2023 08:16
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
… Errors (runatlantis#3729)

* FailOnPreWorkflowHookError

* Fix linting issues
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
… Errors (runatlantis#3729)

* FailOnPreWorkflowHookError

* Fix linting issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation go Pull requests that update Go code
Projects
None yet
2 participants