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.

Passing variables from one task to the next in a workflow

I’m trying to have the published output of tasks in a serial sequence made available to later tasks, and have looked at the examples and tried to follow them, but am bumping into an error even before it gets to running the tasks, that one of my inputs isn’t defined yet, even though it’s defined by publishing it from a previous task.

How would I go about this more gracefully (and compliant with st2flow?)

Here’s the code:

root@[redacted]]:/opt/stackstorm/packs/default/actions/workflows# st2 execution get 6066484f23fccc3af38f7d9a

    id: 6066484f23fccc3af38f7d9a
    action.ref: default.workflow1
    parameters: None
    status: failed (1s elapsed)
    start_timestamp: Thu, 01 Apr 2021 22:25:19 UTC
    end_timestamp: Thu, 01 Apr 2021 22:25:20 UTC
    result:
      errors:
      - expression: <% ctx(aws_account_id) %>
        language: yaql
        message: Variable "aws_account_id" is referenced before assignment.
        schema_path: properties.tasks.patternProperties.^\w+$.properties.input
        spec_path: tasks.task3.input
        type: context
      output: null

    root@[redacted]]:/opt/stackstorm/packs/default/actions/workflows# cat -n workflow1.yaml

         1	version: 1.0
         2	tasks:
         3	  # [38, 67]
         4	  task1:
         5	    action: custompack.get_info
         6	    next:
         7	      # #d14c83
         8	      - do:
         9	          - task2
        10	        when: succeeded()
        11	        publish:
        12	          - pf_info.result: <% result() %>
        13	  # [140, 217]
        14	  task2:
        15	    action: custompack.create_aws_conn
        16	    input:
        17	      log_level: DEBUG
        18	      account_uuid: [redacted]
        19	      pop: [redacted]
        20	      aws_account_id: [redacted]
        21	      connection_desc: [redacted]
        22	      pf_port: [redacted]
        23	      speed: [redacted]
        24	      vlan: [redacted]
        25	      zone: [redacted]
        26	    next:
        27	      # #fd9d32
        28	      - do:
        29	          - task3
        30	        when: succeeded()
        31	        publish:
        32	          - pf_vc_info.result: <% result() %>
        33	          - pf_vc_info.settings: <% result().settings %>
        34	          - aws_dx_con_id: <% result().settings.aws_connection_id %>
        35	  # [116, 336]
        36	  task3:
        37	    action: aws.directconnect_confirm_connection
        38	    input:
        39	      log_level: DEBUG
        40	      account_id: <% ctx(aws_account_id) %>
        41	      connectionId: <% ctx(aws_dx_con_id) %>

I can’t see anything in that workflow that is publishing aws_account_id, its not published as an output of task2. So you’d need to publish it to your context.

You might want to put a vars section in your workflow and initialise aws_account_id to the value where you put [redacted]. So that essential has set a variable with a default value. And then use it ctx().aws_account_id wherever you want to use it in your workflow.

But just because there is an input varialbe to a task called aws_account_id, that doesn’t publish it to the context as that variable.

Ah, I see…the value I’m seeking is nested in the settings dictionary but you’re right I didn’t explicitly declare it ahead of time through a publish or a workflow variable. A variable of the same name exists as an input for task2 which I thought would place in the context?

OK, well I’ve gotten further but now have a new problem.

I’m defining the parameter for the workflow “aws_account_id” and it’s a string.

The task is expecting a string, but the value itself is just a number. When the string value of the number is passed to the task, it is somehow interpreting it as an integer. So I’m trying to typecast it as a string in the input which is breaking.

The parameter is named “aws_account_id” so to reference it with YAQL I’d need " ctx(aws_account_id) which is accepted when I save the workflow, but results in the “require string, got int”.

I’ve tried using str(ctx(aws_account_id)) but that breaks the workflow saving with Additional properties are not allowed ('_name' was unexpected).

input:
  aws_account_id: <% str(ctx(aws_account_id)) %>

Help?

OK, it turns out that specific error had to do with not properly setting up CORS for my custom URL. Found that in the debugger view. Oy.

I have another question which is semi-related but a different topic, so I’ll close this one and ask anew.