jb27
jb27

Reputation: 93

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?

Upvotes: 7

Views: 13715

Answers (2)

Seven
Seven

Reputation: 197

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)

Upvotes: 5

Szymon Stepniak
Szymon Stepniak

Reputation: 42174

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()

Upvotes: 11

Related Questions