I'm using Jenkins for the release processes. In a freestyle project, I need to show 'To Mail Id' input box to get mail ids to send mail only when 'Send Mail' check box should be checked. For the requirement, I am using 'Formatted HTML' in 'Active Choices Reactive Reference Parameter' to display 'To Mail Id' input box and 'Boolean Parameter' to display the 'Send Mail' check box. And I am referring 'Send Mail' boolean parameter name in 'Referenced parameters' of 'To Mail Id'-'Active Choices Reactive Reference Parameter'.
Using groovy script, based on the boolean parameter, the mail id input text is displayed.
The issue is that the 'Boolean Parameter' check and uncheck switching is not reflecting in 'Active Choices Reactive Reference Parameter'.
How to resolve the same?
Groovy Script used in 'Active Choices Reactive Reference Parameter'
def sendMail = SEND_MAIL;
if (sendMail.equals('on')){
html_to_be_rendered = """<table><tr>
<td>
<label>TO_MAIL_ID</label>
</td>
<td>
<input type="text" class="setting-input" name="value" size="70" id="to_mail_id">
<small>Enter To Mail ID.This is a comma separated list (optional white space after commas) of mail IDs that should receive mails. E.g., ram#example.com, varun#example.com.</small>
</td>
</tr>
</table>"""
return html_to_be_rendered
} else {
html_to_be_rendered =""
return html_to_be_rendered
}
Screenshot #1 - Send Mail Boolean Parameter
Screenshot #2 - To Mail Id Active Choices Reactive Reference Parameter
Please use Active Choices Parameter Instead of Boolean Value.
Although there is no clear plugin documentation for the supported reference parameter in "Active Choices Reactive Reference Parameter", perhaps it supports only Active Choice parameter as reference parameter.
What version of Jenkins are you using? I ran into a same issue via use Active Choices Reactive Parameter on 2.343, but on 2.332 it's a valid case
WA: use Choice Parameter - return ['off', 'on'] or Active Choices Parameter - return ['on'] (via use choice type - check boxes)
Related
`I am using Active Choice Reactive Reference Parameter to get the option loaded based on the previous Active choice parameter(VMConfiguration). However I am able to get a dropdownlist getting just "Ver1", "Ver2", "Ver3".
ad_studio_install = [
"AD Studio Install":
["Ver1", "Ver2", "Ver3"]
]
adstudio_list = ad_studio_install[VMConfiguration]
html_to_be_rendered = """<select name="value">"""
adstudio_list.each { json_file ->
html_to_be_rendered = """
${html_to_be_rendered}
<option value="${json_file}">${json_file}</option>
"""
}
```
I have faced the exact same problem a while back. As I could not get it to work with the Active Choice Parameter Plugin I wrote a plugin dedicated to this purpose. Having a sort of decision tree based choice in drop down boxes.
The only thing you need to do is install the "Multiselect Parameter" plugin and configure it to be used as a parameter in your build, like for example this way:
H,Software product,Selected version
V,SELECTED_SOFTWARE,SELECTED_VERSION
C,AD Studio,Ver1
C,AD Studio,Ver2
C,AD Studio,Ver3
In your build you get the selected values in the given environment variables SELECTED_SOFTWARE and SELECTED_VERSION.
You can even select human readable names for your versions and have a technical value in a variable.
All of this is explained in the documentation and in the help texts.
For Jenkins pipeline, I've a parameter say Repository and second parameter say Branch.
Based on Repository value, I want to auto-populate, value for Branch.
Let's say -
if Repository is BobRepo then for Branch value BobBranch is auto populated
if Repository is AdamRepo then for Branch value AdamBranch is auto populated
This can be achieved using Active Choice Reactive Reference Parameter.
But if user provides, some unknown value to Repository like UnknownRepo then he should be allowed to type in value in Branch parameter which is not possible with Active Choice Reactive Reference Parameter
Can you please help how to achieve editable parameter when conditions don't match?
Actually you can achieve that using the Active Choice Reactive Reference Parameter.
All you need is to set the Branch parameter to be of Choice Type Formatted HTML and use the following template that is provided in the official documentation:
return "<input name=\"value\" value=\"${ReactiveRefParam}\" class=\"setting-input\" type=\"text\">"
This code template will create an input parameter with the propagated value that was defined in the value attribute ,and it enables the user to edit the propagated value.
In your case it will look something like:
def branch = ''
if (Repository == 'BobRepo') {
branch = 'BobBranch'
} else if (Repository == 'AdamRepo') {
branch = 'AdamBranch'
}
return "<input name='value' value='${branch}' class='setting-input' type='text'>"
If you want the input field to be read only on certain values, then it is also possible using the readonly attribute of the HTML input with some logic.
In addition you can also add HTML styles to input as you wish.
Here is an example that prevents edits when a branch is populated and the input width is changed to a custom value:
def branch = ''
if (Repository == 'BobRepo') {
branch = 'BobBranch'
} else if (Repository == 'AdamRepo') {
branch = 'AdamBranch'
}
return "<input name='value' value='${Repository}' style='width: 200px;' class='setting-input' type='text' ${branch ? 'readonly' : ''}>"
step1 - Declared "appname" as choice parameter with 10 values.(single select)
step2 - To get the latest artifact of the above appname, used "artifact_name" as extended choice param
with 'max count-10' delimeter as ','
So the "artifact_name" values , i mean the last artifacts like 10 should be displayed inside
"single select" list box of "artifact_name"
-> Groovy Source script for "artifact_name" value is below.
def filter= "${params.appname}" //Not able to get above declared variable to new variable and use it dynamically in below url to filter the artifacts)
def con = def connection = new URL( "https://hostname/artifactory/source-artifactory/$filter/?list&deep=1&listFolders=0&mdTimestamps=1&includeRootPath=0" )
.openConnection() as HttpURLConnection
So am not able to access the "appname" value and assign it to a new variable like "def filter = "${params.appname}" and use the new variable in connection url for every application name to get the artifacts. S
Hardcoded value working but i have 10 apps can't create ten jobs with hardcoded values.
Does Jenkins support (out of the box plugin) to have a way of defining dependent parameters. For ex: If I have three fields in a choice parameter for user to input, and if I select option A (considering it gives you a list of options) in the first field, then only other dependent fields should be shown to user to fill out(while doing the build), Similarly if user selects B , it should show rest of the other relevant options
Regards
You can do a basic if/then on a source parameter using an Active Choice Reactive Reference parameter. This does not solve the problem of not wanting parameters to display or not though.
How to do an if / then on a build parameter, setting another build parameter
============================================================================
You need the "Active Choices" plugin for starters.
1) The source parameter
Create a typical choice parameter - We'll call it "Choose", and give it the choices "val1", "val2", "val3", "val4"
2) The derived parameter
Create an "Active Choices Reactive Reference Parameter".
Name: What you want the parameter to be called / referenced as
Check "Groovy script"
The script:
if (Choose.equals("val1")) {
return "<input name=\"value\" value=\"Something because we chose val1\" class=\"setting-input\" type=\"text\">"
} else if (Choose.equals("val2")) {
return "<input name=\"value\" value=\"Something because we chose val2\" class=\"setting-input\" type=\"text\">"
} else if (Choose.equals("val3")) {
return "<input name=\"value\" value=\"Something because we chose val3\" class=\"setting-input\" type=\"text\">"
} else if (Choose.equals("val4")) {
return "<input name=\"value\" value=\"Something because we chose val4\" class=\"setting-input\" type=\"text\">"
}
Choice type: Formatted hidden HTML
-- or --
Formatted HTML - For testing so you can see the parameter being set
Referenced parameters: The name of the source parameter - "Choose"
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
}
Can anyone help me with this please?
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()
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)