StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html
https://stackstorm.com/
Apache License 2.0
6.07k stars 749 forks source link

Accessing published variables #3879

Closed sumeetisp closed 6 years ago

sumeetisp commented 6 years ago

Consider following workflows,

Scenario 1:

version: '2.0'
examples.mistral-examples:
    description: A basic workflow that runs an salt command.
    type: direct
    input:
         - payload
        - api_url
    tasks:
        get_box_details:
            action: core.http
            input:
                  ********
                 Some inputs here
                 ********
           publish:
                 result: <% task(get_box_details).result.body %>
        print_result:
               action: core.noop
               publish:
                      output: <% $.result %>`

This above scenario gives an error as follows,

Failed to handle action completion [error=Can not evaluate YAQL expression [expression=$.result

Scenario 2:

 version: '2.0'
 examples.mistral-examples:
    description: A basic workflow that runs an salt command.
    type: direct
    input:
        - payload
        - api_url
    tasks:
        get_box_details:
            action: core.http
            input:
                  ********
                  Some inputs here
                 ********
           publish:
                  result: <% task(get_box_details).result.body %>
           on-success:
               - print_result
        print_result:
               action: core.noop
               publish:
                     output: <% $.result %>

The above scenario executes successfully.

To access variables published by task1 in task2, should task2 be specified in on-success criteria of task1?

If not, then why does scenario 1 fail?

LindsayHill commented 6 years ago

The problem with your first option is that since you don't have any on-success: criteria for get_box_details, it executes tasks in parallel, not sequentially. So it is trying to reference $.result in print_result before it has been published.

See https://docs.stackstorm.com/mistral.html

In this example, we have a second task named “task2”. It might be natural to think that “task2” will be executed after “task1”, i.e, in sequential order. However, when no tasks attributes like on-complete, on-success and on-error are defined, tasks are run in parallel. This is possible with Mistral because it provides a join flow control which allows us to synchronize multiple parallel workflow branches and aggregate their data.