Use output from workflow step

324 views
Skip to first unread message

Marin Gromov

unread,
Aug 30, 2023, 11:43:20 AM8/30/23
to rundeck-discuss
Hello,

Is it possible to get Key Value Data from a workflow step of referred workflow job's step and use it in the main. Essentially I'm looking to do something like this:
1. Job A calls Job B as workflow step with a set of parameters
2. Step 2 of Job B returns some Key Value Data during its execution
3. Job B completes and Job A continues
4. Job A calls jobs C, D,... does some other things
5. Job A calls Job B again as a workflow step with a set of parameters, one of which is the returned data from step 2.

I recall having tried to do this before unsuccessfully as:
- key value data apparently is not passed back up to the main job
- I tried using a GlobalVariable step, but it would return literal variable name of the key value data from the sub-job, instead of its value.

Could someone please provide some insight into what's the correct way to go about this?

Thanks in advance!

Marin

rac...@rundeck.com

unread,
Aug 30, 2023, 1:06:16 PM8/30/23
to rundeck-discuss

Hello there, Marin.

Try “elevating” the data value as an export variable; this allows you to “retake” the data value on the Parent Job Workflow. In your instance, you must create an option in Job B to “receive” the output generated by itself in the second call. It sounds dizzy, but here’s an example for you to try:

Parent Job: Calls ChildJobA, which generates a data value and an exported value to use later (this value is available for every Parent Job workflow), then calls ChildJobB, and finally calls ChildJobA again, but this time passing the exported value in the first step.

- defaultTab: nodes description: '' executionEnabled: true id: 8042e48f-54e9-4d98-8840-b77754eb34d7 loglevel: INFO name: ParentJob nodeFilterEditable: false plugins: ExecutionLifecycle: null scheduleEnabled: true sequence: commands: - exec: echo "starting..." - jobref: group: '' name: ChildJobA uuid: d0196853-4bc4-41f9-8e48-69b997d14338 - jobref: group: '' name: ChildJobB uuid: 6eee7f24-2b0a-4e70-8f0e-e05629d5aeae - jobref: args: -car_brand ${export.the_car_brand} group: '' name: ChildJobA uuid: d0196853-4bc4-41f9-8e48-69b997d14338 keepgoing: false strategy: node-first uuid: 8042e48f-54e9-4d98-8840-b77754eb34d7

ChildJobA: Creates a data value, this value is exported in a “global variable” to use it later in the Parent Job Workflow.

- defaultTab: nodes description: '' executionEnabled: true id: d0196853-4bc4-41f9-8e48-69b997d14338 loglevel: INFO name: ChildJobA nodeFilterEditable: false options: - name: car_brand plugins: ExecutionLifecycle: null scheduleEnabled: true sequence: commands: - exec: echo "Child Job A" - exec: echo "car=fiat" plugins: LogFilter: - config: invalidKeyPattern: \s|\$|\{|\}|\\ logData: 'true' regex: (.*)=(.*) replaceFilteredResult: 'false' type: key-value-data - configuration: export: the_car_brand group: export value: ${data.car*} nodeStep: false type: export-var - exec: echo ${export.the_car_brand} - exec: 'echo "the parameter from Parent Job: ${option.car_brand}"' keepgoing: false strategy: node-first uuid: d0196853-4bc4-41f9-8e48-69b997d14338

ChildJobB: Just a simple job, prints a random string.

- defaultTab: nodes description: '' executionEnabled: true id: 6eee7f24-2b0a-4e70-8f0e-e05629d5aeae loglevel: INFO name: ChildJobB nodeFilterEditable: false plugins: ExecutionLifecycle: null scheduleEnabled: true sequence: commands: - exec: echo "doing something..." keepgoing: false strategy: node-first uuid: 6eee7f24-2b0a-4e70-8f0e-e05629d5aeae

Hope it helps!

Marin Gromov

unread,
Aug 30, 2023, 3:49:11 PM8/30/23
to rundeck-discuss

Appreciate your quick response! I think I get the idea and my syntax was wrong when using the Global Variable step to export the variable "upwards".

I imported your yamls on my test Rundeck instance and got a neat visual of how it *should* look like. I'll test it out tomorrow on the job I'm building and report back, but I'm 99% sure this is my solution.

Thank you and have a good night!

Marin
Message has been deleted

Marin Gromov

unread,
Sep 20, 2023, 7:49:02 AM9/20/23
to rundeck-discuss
Worked like a charm!

One follow up question:
Suppose I have a Job A that calls a Job B, that then calls a Job C and Job C creates a global variable.

Within the runtime of Job A, does that variable become exposed only to the steps of Job B, or to those of Job A as well? I reckon in the former case I'd need to "pass it along" in a Job B step so I can get it up to A..

Thanks in advance!

Marin

rac...@rundeck.com

unread,
Sep 20, 2023, 1:51:45 PM9/20/23
to rundeck-discuss
Hi Marin,

Yes, in that case, the idea is to use options on the "target job" to pass the "elevated data" as an argument.

Regards.
Reply all
Reply to author
Forward
0 new messages