From 8859c36be3eef215e805a7b464babefd076969f6 Mon Sep 17 00:00:00 2001 From: Dan Marshall <16818261+demolitionmode@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:48:57 +0000 Subject: [PATCH] Return the deployment result in exit code for all failures --- samcli/commands/deploy/deploy_context.py | 7 +++---- tests/unit/commands/deploy/test_deploy_context.py | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samcli/commands/deploy/deploy_context.py b/samcli/commands/deploy/deploy_context.py index ac21f5461e..dfd971befe 100644 --- a/samcli/commands/deploy/deploy_context.py +++ b/samcli/commands/deploy/deploy_context.py @@ -280,10 +280,9 @@ def deploy( click.echo(str(ex)) except deploy_exceptions.DeployFailedError: # Failed to deploy, check for DELETE action otherwise skip - if self.on_failure != FailureMode.DELETE: - raise - - self.deployer.rollback_delete_stack(stack_name) + if self.on_failure == FailureMode.DELETE: + self.deployer.rollback_delete_stack(stack_name) + raise else: try: diff --git a/tests/unit/commands/deploy/test_deploy_context.py b/tests/unit/commands/deploy/test_deploy_context.py index cf9e22f2f3..ad5638ef22 100644 --- a/tests/unit/commands/deploy/test_deploy_context.py +++ b/tests/unit/commands/deploy/test_deploy_context.py @@ -248,7 +248,8 @@ def test_on_failure_delete_rollback_stack(self, mock_client, mock_session): self.deploy_command_context.on_failure = FailureMode.DELETE - self.deploy_command_context.run() + with self.assertRaises(DeployFailedError): + self.deploy_command_context.run() self.assertEqual(self.deploy_command_context.deployer.rollback_delete_stack.call_count, 1)