Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make dynamic drop down lists on parameterized build page in a custom Hudson plugin?

Tags:

plugins

hudson

I am trying to achieve the following for a parameterized hudson job: when a user clicks on 'build now' he should be presented with three drop down list parameters viz., Environment, Server, Port. I want the drop down to be dynamic i.e on changing the value of environment the list of servers should change accordingly and similarly the values of port should change on the basis of selected server.

Once a user makes the final selection, all three values from the dropdowns are to be used to make a single value to be passed to the build job as a parameter. I am stuck at how to achieve this in a single parameter and make it dynamic. In my custom plugin i have extended the ParameterDefinition class and within it i have a static nested class extending the ParameterDescriptor class with doFillXXXItems() for these three fields. The values in environment dropdown are populated on the basis of logged in username. I would really appreciate it if somebody could help me figure out how to make the drop downs dynamic. I have already tried the dynamic drop down listbox in ui-samples plugin but its not working in my case :(

like image 244
Momin Avatar asked Feb 13 '11 22:02

Momin


1 Answers

You could inherit hudson.model.ChoiceParameterDefinition, and override its method of getChoicesText. return the options based on whatever you want, in your situation, you could get environments from Hudson.getInstance().

Below snippets is shown how get environment variable.

Hudson.getInstance().getGlobalNodeProperties()
       .get(EnvironmentVariablesNodeProperty.class).getEnvVars().get(name);
like image 97
Andy Horng Avatar answered Nov 15 '22 16:11

Andy Horng