Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user inputs from Jenkins Active Choice parameter using Formatted HTML

I defined parameter of type "Active Choices Reactive Reference Parameter" on Freestyle Job

it returns HTML text input - <input>. but after populating this data and press "Build" i can't get the user input of this text field, tried with groovy or shell steps, for the parameter name itself i get empty string.

it's possible somehow to fetch the value of below field VAPP_ID ? suppose to get "123"

Build parameters options

This is the groovy script of this Formatted HTML:

vappHtml = '''
<ul style="list-style-type: none">
  <li>
    <label for="VAPP_ID">VAPP_ID</label>
    <input type="text" id="VAPP_ID" name="VAPP_ID">
  </li>
</ul>
'''

return vappHtml 
like image 234
Adir D Avatar asked Mar 02 '23 08:03

Adir D


1 Answers

Finally i found what is the exact input definition needed to be able to fetch the data later in build steps.

groovy script:

vappHtml = '''
<ul style="list-style-type: none">
    <li style="padding: 5px">
    <label>VAPP_ID</label>
    <input type="text" class="setting-input" name="value">
  </li>
</ul>
'''

return vappHtml

How to actually fetch the data:

in build steps, like Shell, just get the original build parameter in my case it's $Env_Details

i was missing for 2 mandatory attributes for the <input>

  • class="setting-input"
  • name="value" (the name must be 'value' and nothing else)

Note - In case you want to use multiple input fields, just give all of them the same name attribute: name="value", in the result, it will just give you all the fields values separated by "," delimiter, so you can split it in groovy or something.

Hope it will help someone :)

like image 111
Adir D Avatar answered May 11 '23 09:05

Adir D