Mistral Workflow with Notifications and Parameters

#1

I’ve got a mistral workflow that takes some parameters and also is set to notify on complete so I can do something else with the data after each step completes:

---
name: test_action
entry_point: workflows/test_action.yaml
runner_type: mistral-v2
pack: test_pack
parameters:
  param_1:
    type: string
notify:
  on-complete:
    routes:
      - "to_somewhere"

Corresponding rule:

---
...
trigger:
  type: core.st2.generic.notifytrigger
  parameters: {}
criteria:
  trigger.channel:
    pattern: "to_somewhere"
    type: "equals"
action:
  ref: test_pack.send_somewhere
  parameters:
    message: "{{ trigger }}"

I’ve been trying to figure out the best way to get the parameters fed to the “test_action” workflow to be sent at the end of each task in the workflow and at the end of the workflow itself. Jinja templates such as {{ action_parameters }} or {{ action_context }} etc. in the test_action.yaml notify section don’t seem to work quite right.

So for example, I’ve tried:

notify:
  on-complete:
    routes:
      - "to_somewhere"
  data:
    param: "{{ action_parameters.param_1 }}"

But it seems like it doesn’t render out properly for both the tasks in the workflow and the workflow…it’s one or the other.

I’ve seen in the docs regarding notifications and mistral that per task notifications aren’t fully supported as “first class citizens” and wondering if that’s what’s causing my frustration with this. Also open to suggestion on how to achieve the end result in a different way.

(Lindsay Hill) #2

Looks like some detail got lost in posting there @MickeyPvX?

#3

sorry, working on it!

1 Like
(Lindsay Hill) #4

What’s the end goal here? You want to post a message to Slack that includes some of the original action parameters?

(Lindsay Hill) #5

Because you don’t have to use notify in your workflow.

You could just call test_pack.send_somewhere as another task in your workflow.

#6

Yeah, I played with that a bit, but it seemed like a lot of repetitive blocks of code. Plus, with some of the workflows I’d like to apply this to, they’re fairly complex and just being able to apply a notification on the workflow metadata would be super efficient.

You’ve got the gist of what I’m trying to do; I need live updates on each task and a final message upon workflow completion. The notification as shown above does exactly what I need but without a key piece of data that I’m getting externally.

(Lindsay Hill) #7

Notifications — StackStorm 2.10.4 documentation says:

When the notification triggers are sent out, the message is supplied along with a data field containing the results of the execution. The rule can use these two fields ( message and data ), and send it out as part of the action.

You could try creating a notification rule that dumps out the contents of {{ trigger.data }}, and see what it contains.

#8

The default data contents is the result of each action/workflow, which is useful, but if I want to pass around “param_1” then I’m back to modifying every custom action to include it in its result, and in some cases where actions from, say, the core pack, aren’t readily modifiable, that makes consistency pretty difficult.

Adding to the data dictionary seemed to be what I needed, but when passing in a Jinja template such as:

data:
  env_data: "{{ env() }}"

It gets the correct value for individual actions, but the notification for the workflow completion just returns:

data: {
  result: {<stuff here>},
  env_data: "{{ env() }}" <-- doesn't render for the workflow
}

How I wish there was an “{{ workflow_parameters }}” option :smiley: