Jenkins Dynamic parameters based on previously selected parameter value
Asked Answered
F

7

27

Here I am basically looking for a dependency parameter.

Let's say I have two dropdowns in the build parameter section. Based on the value selected from the first dropdown the possible default I want the values of the second dropdown to vary.

Is there any plugin or approach to handle this requirement effectively?

Fi answered 27/3, 2013 at 7:38 Comment(1)
If I want the second dropdown to take values from the output of a shell script how do i do that?Aubry
S
15

This is exactly what you are looking for: https://github.com/biouno/uno-choice-plugin/wiki/Uno-Choice-Cascade-Dynamic-Choice-Parameter

It seems to be a hidden gem, haven't found it in any of the similar questions so far.

Sycophant answered 1/8, 2014 at 9:11 Comment(1)
Perhaps a bit late but if anyone else needs this, as noted in this similar question the plugin was shared with the Jenkins community and officially renamed to Active Choices PluginHerriott
C
10

Let's keep thing simple, Here is Step by Step process to achieve the required.
1.Install Active Choices Plugin in your Jenkins.
2.Add an ACTIVE CHOICE PARAMETER enter image description here

  1. Add an ACTIVE CHOICE REACTIVE PARAMETER. enter image description here

4.Click on apply and then on save.
Its done. !!!
Do comment if facing any problem with this.

Cephalalgia answered 19/12, 2018 at 11:49 Comment(0)
E
5

I have not used it, but it looks like the following plugin may do what you want:

A Jenkins parameter plugin that allows for two select elements. The second select populates values depending upon the selection made for the first select.

https://github.com/tekante/Dynamic-Jenkins-Parameter/wiki

Exemplar answered 9/4, 2013 at 11:37 Comment(2)
Seems to be quite limited, allows just two choices in the first drop-down, so only two alternative lists for 2nd drop-down.Plica
Its Possible execute Groovy in this plugin?Surcingle
W
5

A new plugin with this capability (and much more) is available here: https://wiki.jenkins-ci.org/display/JENKINS/Active+Choices+Plugin

The wiki page contains several usage examples and code

Wollis answered 21/1, 2016 at 15:41 Comment(0)
B
1

This is what you want to achieve right?

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

Here is the similar question.

Bainite answered 27/3, 2013 at 7:58 Comment(1)
The question is about altering the list based on a parameter on the same form. I'm not sure if there is an easy to way achieve this, but I'd love to see some example code about how to do it. The way you (and the linked answer) show uses already existing information defined elsewhere, it's not altering choices dynamically based on another drop-down in the same form.Plica
B
0

This should do the trick it lets you to single select, multiselect and do it in levels https://wiki.jenkins-ci.org/display/JENKINS/Active+Choices+Plugin

Basso answered 13/2, 2017 at 16:43 Comment(0)
L
0

Here is the example, I'd like to find when I was looking for this question ;

Here is the way to create an active choice reactive parameter with Jenkins job DSL.

activeChoiceReactiveParam('PARAMETER_NAME') {
    description('Parameter description')
    filterable()
    choiceType('SINGLE_SELECT')
    groovyScript {
        script('return [ANOTHER_PARAMETER + ".suffix", ANOTHER_PARAMETER + ".suffix2"]')
        fallbackScript('return ["NotFound"]')
    }
    referencedParameter('ANOTHER_PARAMETER')
}

Note: if it doesn't work by importing job via DSL, just "Configure" and "Save". There is a bug: JENKINS-42655

Libya answered 24/10, 2019 at 21:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.