Cascading Options - Multiple values.

253 views
Skip to first unread message

Roger McCarrick

unread,
Mar 11, 2024, 3:18:35 PM3/11/24
to rundeck-discuss
I use cascading options a lot.

My json file for the option "Client", looks like :

[
 {
  "name":"Client1-ABC",
  "value":"ABC.json"
 },
 {
  "name":"Client2-XYZ",
  "value":"XYZ.json"
 }
]

So in the Rundeck drop-down, I can choose Client1-ABC or Client2-XYZ
If I choose Client1-ABC, the next option loads the file:
   $pathToFile/${option.Client.value}
   $pathToFile/ABC.json

Is it possible to have, multiple values in the JSON file, value1, value2 etc?

[
 {
  "name":"Client1-ABC",
  "value":"ABC.json",
 "value2":"US.json"
},
{
  "name":"Client2-XYZ",
  "value":"XYZ.json",
  "value2":"UK.json"
 }
]

In this case if I chose Client1-ABC, I want one option to load :
   $pathToFile/${option.Client.value}
   $pathToFile/ABC.json

and the next option to load:
   $pathToFile/${option.Client.value2}
   $pathToFile/US.json

So I want the Client option to be determine 2 other options.

I have tried the above, but I get error:
Exception: java.net.URISyntaxException: Illegal character in path at index 71: file:PathToFile/${option.Client.value2}

Any other way to do it?

Thanks

rac...@rundeck.com

unread,
Mar 11, 2024, 4:38:11 PM3/11/24
to rundeck-discuss
Hi Roger

Is it possible to have, multiple values in the JSON file, value1, value2 etc?

No at this moment. Rundeck only admits this format. You can file a new request here.

The current way is still passing by dependency in your options choice.

Regards.

Roger McCarrick

unread,
Mar 11, 2024, 4:46:45 PM3/11/24
to rundeck-discuss
Ya, I have been looking at this and there's the bit on " Using Nested JSON Elements  "
" When the required JSON elements return from the remote URL are nested, then use the Json Path Filter field"

{ "key1":"value1", "key2": { "sub-key3":"value3", "sub-key4":"value4" } }

Then, the list of key-value pairs from key2 can be accessed with $.key2
Is this saying that I can get value1 with   $pathToFile/${option.Client.key1}  ?
Or value3 with   $pathToFile/${option.Client.key2.sub-key3}  ?

rac...@rundeck.com

unread,
Mar 12, 2024, 3:22:22 PM3/12/24
to rundeck-discuss

Hi Roger,

That is for taking the options from a nested JSON block. So, you will reference that in the same way {option.option_name} on the command step, but if you want to use it in a cascade, same:  file:/path/to/your/json/{option.option_name.value}. In this context, “value” isn’t the value name, is the Rundeck variable to refer to the value on the key/value structure.

e.g:

Job definition:

- defaultTab: nodes description: '' executionEnabled: true id: f7f8039a-17ff-4bbe-a683-95a25b739018 loglevel: INFO name: Cascade nodeFilterEditable: false options: - name: opt1 valuesUrl: file:/home/user/parent.json - name: brands valuesUrl: file:/home/user/${option.opt1.value} plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - exec: echo ${option.ropt} keepgoing: false strategy: node-first uuid: f7f8039a-17ff-4bbe-a683-95a25b739018

See that “value” is the variable to access the value of the JSON registry, not the name “value”.

parent.json JSON file:

{ "brands": "brands.json", "services": "services.json" }

services.json JSON file:

{ "service_1": "Service1", "service_2": "Service2", "service_3": "Service3" }

brands.json JSON file:

{ "brand_1": "Brand1", "brand_2": "Brand2", "brand_3": "Brand3" }

Now, I have been testing this specific way to use options (nested) and it works only on HTTP remote options, I think that should be working on file options too. I’ll file a new issue related.

Regards.

Roger McCarrick

unread,
Mar 12, 2024, 4:59:20 PM3/12/24
to rundeck-discuss
Not sure what you are doing here,  I ran it and it just fails. But it looks like normal cascade options,
i don't know what " option.ropt  "is.

But I searched this group and came across https://groups.google.com/g/rundeck-discuss/c/9NPAxOcM5p8
and added a reply. But basically following on the suggestion of making the value of an option equal to the result of a command using JQ to extract a value.
" Getting the JSON values in an inline script through JQ to extract the desired values based on initial options values in your job is probably the best approach."
I just dont know how to do it.

rac...@rundeck.com

unread,
Mar 12, 2024, 5:28:02 PM3/12/24
to rundeck-discuss

My bad, wrong job definition in my last post, this is the right one:

- defaultTab: nodes description: '' executionEnabled: true id: f7f8039a-17ff-4bbe-a683-95a25b739018 loglevel: INFO name: Cascade nodeFilterEditable: false options: - enforced: true name: opt1 valuesUrl: file:/home/user/parent.json - enforced: true name: brands valuesUrl: file:/home/user/${option.opt1.value} plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - exec: echo ${option.brands} keepgoing: false strategy: node-first uuid: f7f8039a-17ff-4bbe-a683-95a25b739018

That was to demonstrate that the variable “value” (${option.my_opt.value}) refers to the JSON value, not the value name provided in the JSON file.

Regards.

Roger McCarrick

unread,
Mar 12, 2024, 7:22:14 PM3/12/24
to rundeck-discuss
So you are saying ${option.my_opt.value} refers to the value of the option "my_opt" and not to the key "value" in the JSON file?

OK

and you didn't put name and value in your JSONs
"service_1": "Service1",
instead of 
"name":"service_1", "value":"Service1"

how does rundeck know which to is the name and which is the value?



rac...@rundeck.com

unread,
Mar 13, 2024, 8:10:35 AM3/13/24
to rundeck-discuss

Hi Roger,

In that scenario, Rundeck uses the first registry element as a key and the second as the value. After some experimentation, I realized that I had forgotten a “workaround” for selecting several items as keys.

The “trick” is to set the second option to “multiple-valued” followed by a comma. In that way, you can select numerous alternatives; however, unlike your original request, this method requires you to include every option provided in the JSON file as registers.

parent.json JSON file:

{ "brands": "brands.json", "services": "services.json" }

services.json JSON file:

{ "service_1": "Service1", "service_2": "Service2", "service_3": "Service3" }

brands.json JSON file:

{ "brand_1": "Brand1", "brand_2": "Brand2", "brand_3": "Brand3" }

Job definition

- defaultTab: nodes description: '' executionEnabled: true id: 0e388143-065a-426b-9cf3-911aaf2405a2 loglevel: INFO name: HelloWorld nodeFilterEditable: false options: - enforced: true name: parent value: services valuesUrl: file:/home/user/parent.json - delimiter: ',' multivalued: true name: select values: - file:/home/user/${option.parent.value} valuesListDelimiter: ',' valuesUrl: file:/home/user/${option.parent.value} plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - exec: 'echo "selected items: ${option.select}"' keepgoing: false strategy: node-first uuid: 0e388143-065a-426b-9cf3-911aaf2405a2

See how to select multiple elements and the job result.

Hope it helps.

Reply all
Reply to author
Forward
0 new messages