Need to select multiple values as default dynamically in jenkins - jenkins

In a prameter need to select multiple values as default dynamically in jenkins. Because need to run a scheduler on which multiple values should be selected as default. Any suggestion please.

You can use Extended Choice Parameter Plugin to select multiple valued for a variable.
After installing the plugin, in your project configuration page select This Project is Parameterized option and then from the drop-down choose Extended Choice Parameter.
Then add a name for your parameter and choose the parameter type as Multi Select. Then under Choose Source for Value section choose from where you want to take the vales for your parameter and save your job. In the following image I am providing the value in the job itself. You can choose alternate methods.
Now when you build your project you can select multiple values.

you can try to use source for default value

I would suggest Active Choices instead, using for example a simple checkbox configuration

Related

Dynamic parameter selection on jenkins

I have a build/deploy job on jenkins, and user can select multiple items to be deployed with multi select parameter. I retrieve those values dynamically from db table with a groovy script.
Problem is that some of the variables should be linked. Meaning; when user selects item X, item A and item B also should be selected.
Is there a way of triggering a selection event on jenkins multi select? or should I use something else?
Thanks.
After spending some time I found a way to do this using Active Choices Plugin
1- I kept my initial extended choice parameter lets name it COMPONENTLIST
2- Then I created another paramateter as Active Choices Reactive Reference Parameter lets name it COMPONENT_IDS
2a- I added COMPONENTLIST as referenced parameter in COMPONENT_IDS. And set the Choice Type as Formatted HTML and also selected Omit value field
2b- I used following groovy script to collect initial selection and make modifications on it and returned as in step 2c
def output = COMPONENTLIST.split(',').collect{it as int}
2c- tricky part here! It is different how you pass the paramater to build stage. Following line helped me to pass COMPONENT_IDS to build.
output = output.join(",")
return "<b>${output}</b><input type=\"hidden\" name=\"value\" value=\"${output}\" />"

Jenkins control on multiple choice parameter to list the apps

I have a requirement in Jenkins as below.
1) Select environment in choice parameter i.e. prod/staging/sit
2) Based on the above environment value, I need to run execute .SH file to fetch the list of deployed applications from my runtime.
3) Populate the retrieved data again in to a choice parameter and allow user to submit for any start/stop action.
Is it possible in Jenkins to trigger an action based on user selected value in choice parameter? something like AJAX....
it is possible in Jenkins to do a choice active based choices.
you need to add a parameter named "Active Choices Reactive Parameter"
in this parameter there is a field named "Referenced Parameter",
whenever this value is changed the Parameter get's reevaluated based on the changed value

Save values in parameterized build

I am using parameterized build in Jenkins? Is there a way when changing the values of parameters (String parameters for example) to save them for next build instead of using the default?
You can use Extended choise parameter plugin and set default value source to file as described in another question.

read data from file and use the data as multiple checkboxes in extended choice parameter in Jenkins

I have a file with a list of cases that i would like to be able to use as multiple selection check box in my Jenkins project.
example: jenkins.properties
case01_successful_Connection
case02_successful_Disconnection
case03_unsuccessful_Connection
...
The list of cases (in the file) can be from time to time get bigger or smaller!
So, how can Jenkins now read those cases and create during "Build with parameters" the needed check boxes so that the user can select or not the cases?
How should the properties file look like?
Which plug-in should i use to achieve this?
Use the Extended Choice Parameter plugin
Setup new parameter, let's call it mychoice
Select "Type" as Checkboxes
Choose a "Delimeter", for example ,
Under "Choose Source for Value", select Property File
Specify location of property file, it has to be an absolute location, not relative.
Specify "Property Key" that's in the property file, for example "mychoice_values"
Type the following in your property file:
mychoice_values=choice1,choice2,choice3
Every time "Build with parameters" is invoked, it will read that property file, find line that starts with mychoice_values, and will present 3 checkboxes called choice1, choice2, and choice3.
If the property file changes, new choices will be presented
With the answer from Slav and my additional settings I managed to solve my question:
In addition:
1. i added "Default Value" = None
2. i added in the property file: mychoice_values=choice1,choice2,choice3,None (None)
With the above settings 4 check boxes are created and by default the None check box is pre-selected!
It is not perfect the solution, because the user has to uncheck the None box if he checks other boxes! Prefect would be, if None check box would be unchecked automatically when other check boxes are selected!!!

Jenkins Parameterized build to use key/value pairs

I have a Jenkins parameterized build. I tick the "this build is parameterized" and I set a "Choice" environment name to be "ENVIRONMENT" and then as choices I define human readable names such as "Test env1", "Test env2", etc. However I want these keys to actually contain different values, for example "Test env1" key would container a file path as its value. How can this be done?
I have managed to get the keys/values with a dropdown select parameter working with the Active Choices Plugin, the answer was actually buried in the comments on the plugin page itself.
You simply need to use a map rather than a list when writing your groovy script to define the dropdown options. The map key is what the parameter will be set to if the user selects this option. The map value is what will be actually displayed to the user (i.e something human readable) in the dropdown list.
Here are the steps.
Ensure you have the Active Choices Plugin installed.
Open the configuration of your Jenkins job, select This project is parameterised.
Click Add Parameter and select Active Choices Parameter.
Name your parameter ENVIRONMENT and click the Groovy Script check box.
In Groovy Script enter content: return ['env1 file path value':'Test env1', 'env2 file path value':'Test env2'] For this example the user will see a dropdown with 2 options: Test env1 and Test env2. The keys: env1 file path value and env2 file path value are what the Jenkins build parameter will be set to if the option is selected. Modify these as necessary.
In this case ENVIRONMENT is the key and "Test env1", "Test env2", etc. are the possible values. Choice parameter is to restrict the possible inputs.
Based on the value of %ENVIRONMENT% you can execute multiple pathways in your batch scripts or whichever scripts you are executing

Resources