-
Notifications
You must be signed in to change notification settings - Fork 13
Using Uno Choice for Dynamic Input Text Box Defaults
A new functionality provided by the Uno-Choice Dynamic Reference parameter in v 0.18 is the ability to generate a dynamically updated input text box. To my knowledge, this is the first Jenkins UI control that has the ability to do this.
This is really significant, as it allows you to provide dynamic default options that are also editable by the user.
Note that a Jenkins String (or text) parameter can provide a default value but it is static.
Originally, we envisioned using reference parameters only for reference and not participating in the build, but this was short-sighted! It is much more valuable to have dynamic reference parameters that can be passed as parameters to the build.
This page describes how to setup an Uno-Choice parameter so it is rendered as an update-able input box that can also display dynamically generated default values.
Pay attention to the configuration of the element type. You must select the Formatted HTML option. This is really powerful and it allows you to render any properly formatted HTML on the Jenkins build page.
Also, by including DATA_RUN
and PROPERTIES
in the referenced parameters box we will trigger a cascading update that will recompute the PROP_VALUE parameter returned by the groovy script each time either of these two referenced parameters changes.
Write a groovy script that returns your dynamic reference value as a well formatted HTML String. The trick for formatting a text input box is to format the HTML in a way that reflects the HTML Jenkins uses to display parameters in a job submission form. The easiest way to do this is to review the HTML Jenkins uses to display an existing String parameter.
As an example, I will use the WHAT_IS_THIS
string parameter in one of my projects.
Note that WHAT_IS_THIS is a standard Jenkins String parameter.
In Chrome, I select it, right click on it and use 'Inspect Element' to review its underlying HTML. When I do this I see something like this:
So I write my groovy script to return the following formatted HTML:
return "<input name=\"value\" value=\"${dynRefParam}\" class=\"setting-input\" type=\"text\">"
Note that dynRefParam
is the value that my groovy script dynamically generates and refreshes based on the referenced parameters (DATA_RUN,PROPERTIES in this case).
So here is how the PROP_VALUE parameter is rendered in the Jenkins UI.
Note that it refreshes with a new value each time the PROPERTIES option changes!
and when another PROPERTIES option is selected...
In addition, the user can directly modify this dynamic default value !
This is also new in Uno-Choice!
Using the exact procedure shown above, we can generate a hidden parameter that can be passed to the build. The only difference is that this parameter will not be shown in the Jenkins job form UI.
Why would you want to do this?
Imagine that this is a dynamic parameter that your build needs. You want to generate it from the referenced parameters of the UI but you don't want to display it to the user.
To do this simply check the hidden option in the Uno-Choice configuration
I hope this can help you get started using the unique features that Uno-Choice Reference Parameters now make possible.
In the GIF file below you can see that the second parameter is not displayed, since it has been marked as hidden. However, once the job is triggered the hidden parameter value is passed to the build as any other normal parameter.