From bc76f6069b9848811d1dd78b6f0917ee4a434c67 Mon Sep 17 00:00:00 2001 From: Daigo Tanaka Date: Mon, 4 Jan 2021 00:03:11 -0800 Subject: [PATCH] fix: exit cleanly on fail and still push aritfacts (#77) --- handoff/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/handoff/__init__.py b/handoff/__init__.py index 690cdcf..a568073 100644 --- a/handoff/__init__.py +++ b/handoff/__init__.py @@ -178,7 +178,12 @@ def _run_task_subcommand( LOGGER.info("Job started at " + str(start)) # Run the command - commands[command](config, **kwargs) + exit_code = 0 + try: + commands[command](config, **kwargs) + except Exception as e: + LOGGER.error(str(e)) + exit_code = 1 end = datetime.datetime.utcnow() LOGGER.info("Job ended at " + str(end)) @@ -187,7 +192,9 @@ def _run_task_subcommand( os.chdir(prev_wd) - if push_artifacts: + push_artifacts_on_fail = config.get("deploy", {}).get( + "push_artifacts_on_fail", True) + if push_artifacts and (exit_code == 0 or push_artifacts_on_fail): if not state.get_env(BUCKET): raise Exception("Cannot push artifacts. BUCKET environment" + "variable is not set")