Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building project with Active Choice Reactive Reference Parameter

I'm new to jenkins and groovy and I'm trying to create my own configuration which allows me to build my project with various parameters. To achieve that I use Active Choices Reactive Reference Parameter. As a Choice Type I set "Formatted HTML". It looks exactly as I want but unfortunately, no mater what, I cannot return parameters to build.

This is my groovy script:

if(useDefaultValues.equals("YES")) {
    return "defaultName"
 } else {
    inputBox = "<input name='name' class='setting-input' type='text'>"
    return inputBox
 }

This is how my configuration looks

Build with default parameters

Build with other parameters

Can anyone help me with this please?

like image 895
jb27 Avatar asked Aug 13 '18 07:08

jb27


2 Answers

Update your Groovy script to something like this:

def defaultName = "default name"

if (useDefaultValues.equals("YES")) {
    return "<b>${defaultName}</b><input type=\"hidden\" name=\"value\" value=\"${defaultName}\" />"
 }

return "<input name=\"value\" class=\"setting-input\" type=\"text\">"

It's important that your input field uses name value - it does not change your parameter name, and if you named it name you will be able to access it as $name (if you use Groovy for instance).

It is also important that default value is passed as a hidden input field, otherwise parameter value is not set. This hidden input also has to use name value.

However there is one weird problem with HTML formatted input parameter - it always adds , in the end of the parameter value. So for instance if I pass lorem ipsum, when I read it with the parameter $name I will get lorem ipsum,. It looks like it treats it as a multiple parameters or something. To extract clean value from the parameter you can do something like (Groovy code):

name.split(',').first()
like image 151
Szymon Stepniak Avatar answered Oct 03 '22 01:10

Szymon Stepniak


def defaultName = "default name"
if (useDefaultValues.equals("YES")) {
    return "<input type=\"text\" name=\"value\" value=\"${defaultName}\" />"
}
return "<input name=\"value\" type=\"text\">"

Check "Omit value field" fixed comma problem.(comma issue)

like image 44
Seven Avatar answered Oct 02 '22 23:10

Seven