read data from file and use the data as multiple checkboxes in extended choice parameter in Jenkins - 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!!!

Related

Is there a method to display dynamic information to the user BEFORE a build?

Within the Jenkins UI, on the project page, you can use the Description Setter plugin to set a description AFTER a build. Is there any way to dynamically set this before a build? I would want to pull information from a file in the workspace that shows information about files that will be changed when the user builds the project.
Edit: While I haven't found a way to dynamically set the project description, I did find that I can create an Active Choices Reactive Reference Parameter, give it a descriptive name that serves as a title, and then read the contents of a file containing HTML with a Groovy script like so..
// The contents of the file should be HTML
String contents = new File('/tmp/some_file.html').text
return contents
So I made this my last parameter, and it shows the information that I need to show, before the end user clicks the build button. Solves my problem.
I'm going to leave this question open though, in case someone has a better idea.
While I haven't found a way to dynamically set the project description, I did find that I can create an Active Choices Reactive Reference Parameter (this requires the Active Choices plugin),
Give it a descriptive name that serves as a title, and then read the contents of a file containing HTML with a Groovy script like so..
// The contents of the file should be HTML
String contents = new File('/tmp/some_file.html').text
return contents
You will need to select a Choice Type of: Formatted HTML.
So I made this my last parameter, and it shows the information that I need to show, before the end user clicks the build button. Solves my problem.

Need to select multiple values as default dynamically in 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

Newly created build process parameters not showing up

When I add a new parameter in the Process Parameter Metadata Editor, checkin my changes, and go back to edit the definition or queue a build from it, the parameter is not showing. Here is the parameter in the editor:
Other custom parameters I added in the past show up fine. For example, this one shows up fine:
So..I would expect my new parameter to show up the same way this one works.
I tried closing and re-opening VS2013 (I have update 4) and changing to another build controller, but get same behavior. How do I fix this?
A parameter must be defined at the Build Arguments level (the place you found the Build Parameters Metadata).
Afterwards, the Metadata defines how it shows up, which editors it uses, and what description should be shown on it.
That's about the metadata, but you need to add your parameter in the Arguments tab.
You will find it in the XAML Workflow editor at the bottom three buttons/tabs: Variables, Arguments and Imports.

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

Custom Action in Deployment Project - prompt user for values, and then extract them from custom actions?

I am building a Windows Service which will be deployed on four servers. My user wants to have the service read a configuration file from a common location, and load it OnStart.
I want the installation to prompt the user for the file path and file name to the configuration file when the service is installed, and then save that data in My.Settings.
I have figured out how to set the EDITA1 and EDITA2 variables in the Deployment project's UI, so that the user will be prompted for path and file name, but I don't know how to get those values out and into the settings of the service.
Help, please.
-Jennifer
Did you try passing it to the custom action using CustomActionData Property in the Custom Action property window. syntax is /param=[EDITA1]
Context.Parameters will contain a dictionary with 1 entry key being "param" (in my example above that's the key I gave it).
I'm having a problem with passing in parameters which contain spaces. the guidelines say:
For custom actions that are installation components (ProjectInstaller
classes), the CustomActionData property takes a format of /name=value.
Multiple values must be separated by a single space: /name1=value1
/name2=value2.
If the value has a space in it, it must be surrounded by
quotes: /name="a value".
Windows Installer properties can be passed using the bracketed syntax:
/name=[PROPERTYNAME].
For Windows Installer properties such as [TARGETDIR]
that return a directory, in addition to the brackets you must include quotes
and a trailing backslash: /name="[TARGETDIR]\".
When I try the "[EDITA1]\" for the file path I need.. I get the 'FileNotFound' error for "C..\Microsoft..." while my path didn't have Microsoft

Resources