From a67d86ba7fcdf0363e87ac9f6eddf60baabda9ff Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Tue, 7 Nov 2023 14:47:25 +0100 Subject: [PATCH 1/2] Return >0 if the autosubmit command fails --- autosubmit/autosubmit.py | 8 ++++++++ bin/autosubmit | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index fa565a28e..f4feb04d8 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -2075,6 +2075,8 @@ class Autosubmit: try: if Autosubmit.exit: Autosubmit.terminate(threading.enumerate()) + if job_list.get_failed(): + return 1 return 0 # reload parameters changes Log.debug("Reloading parameters...") @@ -2276,6 +2278,12 @@ class Autosubmit: if profile: profiler.stop() + # Suppress in case ``job_list`` was not defined yet... + with suppress(NameError): + if job_list.get_failed(): + return 1 + return 0 + @staticmethod def restore_platforms(platform_to_test, mail_notify=False, as_conf=None, expid=None): Log.info("Checking the connection to all platforms in use") diff --git a/bin/autosubmit b/bin/autosubmit index d3775fbb1..de9c86d3b 100755 --- a/bin/autosubmit +++ b/bin/autosubmit @@ -34,9 +34,11 @@ from autosubmit.autosubmit import Autosubmit # noinspection PyProtectedMember def main(): try: - Autosubmit.parse_args() + return_value = Autosubmit.parse_args() if os.path.exists(os.path.join(Log.file_path, "autosubmit.lock")): os.remove(os.path.join(Log.file_path, "autosubmit.lock")) + if type(return_value) is int: + os._exit(return_value) os._exit(0) except AutosubmitError as e: if os.path.exists(os.path.join(Log.file_path, "autosubmit.lock")): -- GitLab From 1ca8810a62a5875f421c1919230374d0533a50ab Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Thu, 9 Nov 2023 14:42:03 +0100 Subject: [PATCH 2/2] Add documentation about exit status of autosubmit run --- docs/source/userguide/run/index.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/source/userguide/run/index.rst b/docs/source/userguide/run/index.rst index a3b7984ad..e61e62f23 100644 --- a/docs/source/userguide/run/index.rst +++ b/docs/source/userguide/run/index.rst @@ -12,7 +12,9 @@ Launch Autosubmit with the command: ssh-add ~/.ssh/id_rsa autosubmit run EXPID -*EXPID* is the experiment identifier. +In the previous command output ``EXPID`` is the experiment identifier. The command +exits with ``0`` when the workflow finishes with no failed jobs, and with ``1`` +otherwise. Options: :: @@ -40,7 +42,7 @@ Example: ssh-add ~/.ssh/id_rsa autosubmit run cxxx -.. important:: If the autosubmit version is set on autosubmit.yml it must match the actual autosubmit version +.. important:: If the autosubmit version is set on ``autosubmit.yml`` it must match the actual autosubmit version .. hint:: It is recommended to launch it in background and with ``nohup`` (continue running although the user who launched the process logs out). .. code-block:: bash -- GitLab