This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Get result of action in Stackstorm

I am creating a Stackstorm workflow where I want to get the stdout result from one task and compare it in an other task.
But I can’t manage to retreive the result value of my action.
Sample code:

actions/workflow/do_stuff.yaml


version: 1.0
description: do_stuff.

input:
  - stuff

tasks:
  do_stuff:
    action: "core.local"
    input:
      cmd: "/usr/bin/do_stuff '{{ ctx('stuff') }}'"
      timeout: 600

    next:
      - publish:
        - stdout: "{{ result()['stdout'] }}"
        - stderr: "{{ result()['stderr'] }}"
      - when: <% failed() %>
        do: fail


output:
  - stdout: "{{ ctx('stdout') }}"
  - stderr: "{{ ctx('stderr') }}"

actions/do_stuff.yaml

---
name: do_stuff
pack: stuff_pack
description: do some stuff
runner_type: orquesta
entry_point: workflows/do_stuff.yaml
enabled: true
parameters:
  stuff:
    required: true
    type: "string"
    description: "the stuff"

actions/workflow/lifecycle.yaml

version: 1.0

description: The stuff workflow

vars:
  - stuff_result_stdout: null

tasks:

  first_task:
    action: "stuff_pack.do_stuff"
    input:
      stuff: "parameter"

    next:
      - publish:
          - stuff_result_stdout: <% result().stdout %>
      - when: "{{ succeeded() }}"
        do:
          - "second_task"

  second_task:
      action: core.echo message="msg-{{ ctx().stuff_result_stdout }}-"

On the Stackstorm web UI, i clearly see the output of my command (/usr/bin/do_stuff)

with this line stuff_result_stdout: <% result().stdout %>
I have the error YaqlEvaluationException: Unable to resolve key 'stdout' in expression '<%result().stdout %>' from context.

and when I try to get only result(), and print it, I have None.

How do I retreive the output of my action in first_task?

You might be looking in the wrong place for your error.

What is the result() in the do_stuff task in the do_stuff workflow? What is the value of result()['stdout'] from that task?

I had a small error in my lifecycle.yaml:
if you publish and then do a when, the published variable is innacessible

you have to do

first_task:
    action: "stuff_pack.do_stuff"
    input:
      stuff: "parameter"

    next:
      - when: "{{ succeeded() }}"
        publish:
          - stuff_result_stdout: <% result().stdout %>
        do:
          - "second_task"

and then on next task you can get ctx().stuff_result_stdout

I didn’t found much documentation about this context and when variables are accessible or not, which made me do a lot of trial and error.