Update st2 run command to also display result (result of the last task /
action inside the workflow) for workflow actions on completion.
Before this change user would need to manually introspect last task
using st2 execution get command to see the result.
@@ -356,14 +356,15 @@ class ActionRunCommandMixin(object):
# No child error, there might be a global error, include result in the output
options['attributes'].append('result')
- # On failure we also want to include error message and traceback at the top level
- if instance.status == 'failed':
status_index = options['attributes'].index('status')
+
if isinstance(instance.result, dict):
tasks = instance.result.get('tasks', [])
else:
tasks = []
+ # On failure we also want to include error message and traceback at the top level
+ if instance.status == 'failed':
top_level_error, top_level_traceback = self._get_top_level_error(live_action=instance)
if len(tasks) >= 1:
@@ -388,6 +389,15 @@ class ActionRunCommandMixin(object):
options['attributes'].insert(status_index + 2, 'traceback')
options['attributes'].insert(status_index + 3, 'failed_on')
+ # Include result on the top-level object so user doesn't need to issue another command to
+ # see the result
+ if len(tasks) >= 1:
+ task_result = self._get_task_result(task=tasks[-1])
+
+ if task_result:
+ options['attributes'].insert(status_index + 1, 'result')
+ instance.result = task_result
+
# print root task
self.print_output(instance, formatter, **options)
@@ -460,6 +470,12 @@ class ActionRunCommandMixin(object):
return error, traceback
+ def _get_task_result(self, task):
+ if not task:
+ return None
+
+ return task['result']
+
def _get_action_parameters_from_args(self, action, runner, args):
"""
Build a dictionary with parameters which will be passed to the action by
