Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins choice parameter with different display

I want to add a choice parameter to a Jenkins job. The list is fixed, but I want the dropbox to display custom value, and not the actual ones (analogous to name of a web page and not its URL).

In the certain case this is the path of the pom.xml file, however, I want to display the module name instead of the full path. An example:

Actual value                         | What I want to be displayed
-------------------------------------|----------------------------
full/path/to/my/modules/pom.xml      | All modules
full/path/to/my/modules/util/pom.xml | Utilities
full/path/to/my/modules/data/pom.xml | Data handling

Thanks for the help in advance!

like image 960
Csaba Faragó Avatar asked Sep 09 '16 08:09

Csaba Faragó


2 Answers

You can do this with the Extended Choice Parameter plugin.

To set it the way you want, under "This build is parameterized", choose Extended Choice Parameter, and set it up like this:

enter image description here

Note it may look a little different depending on what version of Jenkins you have but it shouldn't be too different (this screenshot was on 2.0-beta-2).

like image 187
user1072692 Avatar answered Oct 12 '22 21:10

user1072692


With the Active Choices plugin, you can set this up with a groovy map:

Set a "Active Choices Parameter" with the following groovy script:

return['full/path/to/my/modules/pom.xml' : 'All modules',
'full/path/to/my/modules/util/pom.xml' : 'Utilities',
'full/path/to/my/modules/data/pom.xml' : 'Data handling']

enter image description here

The "value" of the map will be displayed in the build parameters choices: enter image description here

And "key" of the map will be set in the variable:

> echo "$URL"
full/path/to/my/modules/pom.xml
like image 30
A21z Avatar answered Oct 12 '22 20:10

A21z