Global Variable

177 views
Skip to first unread message

Jeremy Vermillion

unread,
Apr 4, 2024, 4:59:32 PM4/4/24
to rundeck-discuss
Good Afternoon,
I have a multi-step Rundeck job, the first step exports a bunch of Global Variables like so...

rundeckglobal.png
I want to pass these variables in to an inline script (powershell) for the second step.

I can currently pass these variables in to arguments in my current job reference steps so I know they are exporting correctly.

Thanks,
Jeremy

Jeremy Vermillion

unread,
Apr 4, 2024, 5:14:00 PM4/4/24
to rundeck-discuss
I want to add that the first step gathering the variables in my job stack is a job reference to another job if that makes a difference.

rac...@rundeck.com

unread,
Apr 5, 2024, 9:58:23 AM4/5/24
to rundeck-discuss

Hi!

The syntax for using options/data values in inline scripts is @option.name@/@data.name@/@export.name@. Anyway, I made an example showing how to elevate this as a global variable in Powershell and pass that global variable to another job using job reference.

The main job generates an example data value and converts it to a global variable in Powershell (also, it calls a Child job, passing that value as an argument). Check the script step, powershell.exe is defined as “invocation string” and .ps1 as extension.

- defaultTab: nodes description: '' executionEnabled: true id: e29d0a11-d58e-4753-b9c9-06d001d3c188 loglevel: INFO name: GlobalVariablePowerShell nodeFilterEditable: false nodefilters: dispatch: excludePrecedence: true keepgoing: false rankOrder: ascending successOnEmptyNodeFilter: false threadcount: '1' filter: 'name: windows ' nodesSelectedByDefault: true plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - exec: echo "customer=john" plugins: LogFilter: - config: invalidKeyPattern: \s|\$|\{|\}|\\ logData: 'true' regex: ^(.*)=(.*)$ replaceFilteredResult: 'false' type: key-value-data - configuration: export: CUSTOMERNAME group: export value: ${data.customer*} nodeStep: false type: export-var - fileExtension: .ps1 interpreterArgsQuoted: false script: echo @export.CUSTOMERNAME@ scriptInterpreter: powershell.exe - jobref: args: -opt1 ${export.CUSTOMERNAME} group: '' name: Child nodeStep: 'true' uuid: d2f4c7a4-f374-4eaf-8c55-49f316fea42d keepgoing: false strategy: node-first uuid: e29d0a11-d58e-4753-b9c9-06d001d3c188

The Child Job (it contains an option to “receive” the global variable content from the parent job via Job Reference Step):

- defaultTab: nodes description: '' executionEnabled: true id: d2f4c7a4-f374-4eaf-8c55-49f316fea42d loglevel: INFO name: Child nodeFilterEditable: false options: - name: opt1 plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - exec: echo ${option.opt1} keepgoing: false strategy: node-first uuid: d2f4c7a4-f374-4eaf-8c55-49f316fea42d

Of course, you can pass the data variable directly to the child job instead of elevating it as a global variable.

Check the result. More info here.

Regards!

Jeremy Vermillion

unread,
Apr 5, 2024, 10:20:57 AM4/5/24
to rundeck-discuss
Thanks so much for your help, I'm kind of mad I didn't figure this out on my own. The resolution for me ended up being I just needed to use 
@export.CUSTOMERNAME@ in my powershell script. I was trying to use ${export.CUSTOMERNAME} 

rac...@rundeck.com

unread,
Apr 5, 2024, 11:26:01 AM4/5/24
to rundeck-discuss
Happy to help!
Reply all
Reply to author
Forward
0 new messages