Jenkins Dynamic parameters based on previously selected parameter value

≡放荡痞女 提交于 2019-12-03 05:13:13

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.

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

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

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

  1. Add an ACTIVE CHOICE REACTIVE PARAMETER.

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

MangeshBiradar

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.

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

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

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