davdomin
davdomin

Reputation: 1219

How to get a parameter depend of other parameter in Hudson or Jenkins

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

Upvotes: 15

Views: 39443

Answers (6)

Sebastian Westemeyer
Sebastian Westemeyer

Reputation: 298

For all of you who stumble upon the same kind of problem (like I did). There is a fairly new Jenkins plugin available that does exactly what is desired here: display a dependent set of drop-downs, updating dependent boxes when a main box changes selection.

Dependent drop-down box example

For your job you just need to follow the following steps:

Install "Multiselect Parameter Plugin"

The "multiselect parameter plugin" can be installed from Jenkins plugin management, the documentation is available on its Jenkins Plugin page.

Add new parameter

  1. Use "Multiselect Parameter" type
  2. Set name to a sensible value
  3. give a short description
  4. configure like shown below:
H,Environment,Machine
V,SELECTED_ENVIRONMENT,SELECTED_MACHINE
T,Development,
C,DEV,DEV1
T,Development,
C,DEV,DEV2
T,Quality Assurance,
C,QA,QA1
T,Quality Assurance,
C,QA,QA2
T,Quality Assurance,
C,QA,QA3
T,Production,
C,PROD,Machine1
T,Production,
C,PROD,Machine2

Use selected values

When you run "build with parameters" in your job, the following boxes are displayed for selection:

Build parameter drop-downs matching the sample project screens

In your build script you can simply use the configured environment variables SELECTED_ENVIRONMENT and SELECTED_MACHINE, which contain the selected values from both select boxes. The "human readable names" configured in T-prefixes rows of CSV configuration are only displayed in select boxes, you still get the technical names like DEV and PROD passed into the environment variables.

Upvotes: 3

kool79
kool79

Reputation: 413

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.

Upvotes: 20

coderatchet
coderatchet

Reputation: 8420

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.

Upvotes: 12

Peter Schuetze
Peter Schuetze

Reputation: 16305

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.

Upvotes: 0

coffeebreaks
coffeebreaks

Reputation: 3817

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:

I would ask the jenkins user list for more information.

Upvotes: 4

Johnny Chen
Johnny Chen

Reputation: 2070

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.

Upvotes: 0

Related Questions