Jenkins: How to show/hide string parameter fields, after checkbox is un/checked?

Texx picture Texx · Oct 6, 2016 · Viewed 7.8k times · Source

I need to create Jenkins job, which installs product.iso on defined machine. I have 2 options: latest.iso (path to it is already known) custom.iso (path have to be determined manually)

Best implementation would be for me a checkbox named: "install custom iso"

When user choose(check) this checkbox - two string parameter fields would appear below (for determine IP and PATH of custom iso.) When user unchecks this checkbox - these two string parameter fields disappear (and default latest.iso would be installed)

I've searched through many Jenkins plugins, but it seems, that none of them allows this kind of action, which is strange to me, because I think, that this type of action is frequently needed.

Is there any simple way to do it? Any help would be appreciated.

Answer

Ayushi Jain picture Ayushi Jain · May 2, 2019

I think this Plugin will help you to make your Parametarized build more dynamic.

The Active Choices plug-in provides additional Jenkins parameter types that can be rendered as user interface (UI) controls in job forms. It supports using system environment variables, global node properties, and you also have at least the Jenkins project in the Groovy context for Freestyle jobs at least.

Once the plugin is installed three new parameter types become available:

  1. Active Choices Parameter

  2. Active Choices Reactive Parameter

  3. Active Choices Reactive Reference Parameter

Active Choices parameters allow users to select value(s) for a job parameter. Parameter values can be:

a) dynamically generated (using Groovy or a Scriptler script)

b) dynamically updated based on other UI parameters

c) multi-valued (can have more than one value)

d) rendered with a variety of UI controls, including dynamic HTML.

For more clarification and examples, Please refer here: https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin