I use the jenkins with active choices parameter
I need that groovy depends on my choice return area where I can write something
I try this
if (test_bench_UID.equals('user_spec')) { inputBox = "<input name='value' class='setting-input' type='text'>" return inputBox }
Where test_bench_UID is name active choices parameter, user_spec is parameter after choosing whom groovy should return input box
You have to add Active Reactive Reference Parameters, and select the choice type of the "Formatted HTML" field
,
don't forget to select the reference field!), and write such a script (
if(refParameter.equals("value")){
inputBox = "<input name='value' class='setting-input' type='text'>"
return inputBox
} else return "<b>else value will be show as text</b>"
You can use the variable by using ${value}.
In your case may be you can try ${user_spec} where ever you want to access it.
Hope it helps.
Related
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' : ''}>"
Is it possible to give multiple values as input in a string parameter in the Jenkins job..?
If yes, what will be the syntax and how are we calling that in a for loop so the values take one after the other.?
This is for a declarative job in Jenkins.
Thank you for the help in advance
parameters {
string(name: "usernames", value: list.join (","), description: "enter the user names")
}
stages{
need the syntax for this --> //for user in usernames list
do
$echo ---> username
this username which print will be called in my curl command one after the other.
so please do help me with the right path
Generally it is only possible to pass one string.
That being said, since you are using strings you can encode whatever data you want in them.
Suppose you want to pass the pipeline a list of strings myList with values ['foo', 'bar', 'baz']. In the calling job you could simply do:
build ... parameters(string(name: "myString", value: myList.join(",")))
which passes 'foo, bar, baz' to the called job. There you could parse it out again:
params.myString.split(',') // results in ['foo', 'bar', 'baz']
To iterate over this, you could use a for-in loop or a list function like each or collect.
In order to iterate over all the elements you receive you can use the each method
stages {
stage("Iterate over parameters"){
script{
def userNames = params.userNamesString.split(',')
userNames.each { user ->
echo "$user"
}
}
}
}
Alternativly (instead of the userNames.each block you can just use a for-in statement:
for(userName in userNames){
echo "$userName"
}
For more informations on this please have a look at the links I included in my previous answer.
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)
I am implementing a negation filter field in Symfony 1.4. with 1 text input and 1 checkbox for negation.
I can access the input value as below
public function addXXXColumnQuery($query, $field, $value)
{
$v = $value['text'];
$n = 'negation_checkbox_true_or_false'; // don't know how?
if ($n === true)
{
$query->addWhere($query->getRootAlias().'.name = ?', $v);
}
else if ($n === false)
{
$query->addWhere($query->getRootAlias().'.name <> ?', $v);
}
}
but I can't figure out how to access the checkbox value.
sfWidgetFormInputFileEditable has a 'with_delete' option that prints a checkbox. Anyone knows where is the code that checks for that value and delete the file?
If I can find that, maybe I can figure that out.
When you create a sfWidgetFormInputFileEditable with the with_delete option set to true, the widget renders an additional checkbox which is named after the file upload widget with a "_delete" suffix.
When the checkbox is checked, the sfParameterHolder of the sfWebRequest object contains a parameter named after the checkbox widget.
So, suppose you have a sfWidgetFormInputFileEditable named "file". In your action, you can see if the delete checkbox is checked using:
$request->hasParameter('file_delete');