2

OK, so I downloaded this plugin:

https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin

And select Multi-Level Single Select as the type of parameters.

The problem is that when I have multiple parameters selected and I want to use these parameters in shell in a build, I can only select the LAST parameter

So if I do $PARAM_NAME it only outputs the last parameters, but I want all the parameters that I selected, not just the last one.

Here is a picture for demonstration enter image description here

aynber
  • 22,380
  • 8
  • 50
  • 63
user3155659
  • 49
  • 1
  • 4

3 Answers3

1

You aren't building the parameter based on the selections, you are navigating to the value that you want. I.E. Country --->State ---->City

You aren't building a CountryStateCity variable, you are stating that the City variable is the value you select.

evilgeenus
  • 11
  • 1
1

I could get the nearest to this by using Extended Choice Parameter > JSON Parameter Type > JSON Parameter Config Groovy Script.

import org.boon.Boon;
def jsonEditorOptions = Boon.fromJson(/{
  disable_edit_json: true,
  disable_properties: true,
  no_additional_properties: true,
  disable_collapse: true,
  disable_array_add: false,
  disable_array_delete: false,
  disable_array_reorder: false,
  theme: "bootstrap3",
  iconlib: "fontawesome5",
  schema: {
   "type": "object",
   "title": "",
   "required": [
    "Locations"
   ],
   "properties": {
    "Locations": {
     "type": "array",
     "format": "table",
     "title": "",
     "uniqueItems": true,
     "items": {
      "type": "object",
      "title": "Location",
      "properties": {
       "Country": {
        "type": "string",
        "propertyOrder" : 1,
        "enum": [
         "USA",
         "Germany",
         "India"
        ]
       },
       "City": {
        "type": "string",
        "propertyOrder" : 2,
        "enum": [
         "New York",
         "Frankfurt",
         "Mumbai"
        ]
       },
       "Neighborhood": {
        "type": "string",
        "propertyOrder" : 3
       }
      }
     },
     "default": [{
      "Country": "USA",
      "City": "New York",
      "Neighborhood": "Times Square"
     }]
    }
   }
  }
  /);

You can visit the plugin page and json-editor.github.io to create and validate your JSON schemas as seen above.

This is how it appears in Jenkins:

enter image description here

Note that however, it still does not provide a context sensitive second column based on what is selected in the first column. The second column rather behaves exactly like the first column where you select from a pre-defined list without any filters.

On printing the variable Location, it returns this JSON:

{"Locations":[{"City":"New York","Country":"USA","Neighborhood":"Times Square"},{"City":"Frankfurt","Country":"Germany","Neighborhood":"Bornheim"},{"City":"Mumbai","Country":"India","Neighborhood":"Vile Parle"}]}
Dibakar Aditya
  • 3,893
  • 1
  • 14
  • 25
0

I met the same problem, so I added a 'row number' column to the parameters file:

    Country         City            Row
    United States   San Francisco   1
    United States   Chicago         2
    Mexico          Mexico City     3
    Mexico          Cancun          4

This way, the plugin returns the row number and I can address that row from the parameters file.

David Kon
  • 65
  • 1
  • 1
  • 6