How to get a parameter depend of other parameter i

2019-01-23 17:13发布

问题:

I have a problems with Hudson because my job needs two params for build the first specifies the environment and can be one of DEV, QA, PROD, and the second is a specific server, this parameter depends on the first one.

By example if I chose environment DEV, the second parameter can be only DEV1,DEV2, MAQ1 . I don't have an idea if a plugin with this functionality exists or I need to make something with groovy. I do not know please help me.

Thank you

回答1:

It appears that Jenkins loads the list of parameters to select when you open the "build project" page. There's no callback happening when selecting a parameter either.

In that case it will be difficult to restrict the second parameter based on the first one without javascript and a custom plugin.

I also looked at those:

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

I would ask the jenkins user list for more information.



回答2:

Try Active Choices Plugin. It is the second name of Uno-Choice plugin, but it is located in official Jenkins repository and does not require UpdateSites Manager plugin. (Both plugins have the same author). Plugin has a great documentation with examples (and gif-demonstration) on the plugin's description page.



回答3:

A good plugin (requires you to have the UpdateSites Manager plugin and register the biouno update site) is the uno-choice plugin ( and friends).

The Uno-Choice Cascade Dynamic Parameter Plugin plugin allows for not only more than two levels of dependencies, but can generate dynamic content for the parameters which depend on previous input using either scriptler or inline groovy.

This is certainly much more capable than the previous answers.



回答4:

You can try the EnvInject Plugin.

First you put the first parameter into a settings file.Then the plugin can read from the file .Step two,generate the second parameter with your own script.



回答5:

I ran into similar problems. I have a parameter for the environment Dev1, Dev2, ..... and a second one for the server where I need to run the job. I can compute the second from the first, but then the job is already running and I can't move it to another server anymore.

So I ended up having the two parameters with all possible choices and teaching the users to only choose the valid combinations. I can test during script execution whether the combination is valid. I also put a small html table in the comment of one of the parameters which contains valid combinations.

In your case, can you compute the value of the first parameter from the values of the second parameters? Then you would be able to compute (if still necessary) the value of the first parameter, write it to a temporary properties file and load it with the EnvInject plugin in a later build step.