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

妖精的绣舞 提交于 2019-12-06 00:37:51

问题


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 :(


回答1:


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);


来源:https://stackoverflow.com/questions/4987368/how-to-make-dynamic-drop-down-lists-on-parameterized-build-page-in-a-custom-huds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!