Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve parameters from properties file

I have several Jenkins parameterized jobs that uses the same parameters and parameters values. When I have to change the default value of one of those parameters, I need to go over all of those jobs and reconfigure them.

A simple solution to this problem would be an option to retrieve all parameters from config file (in the master/ in the workspace) but I could not find a sufficient implementation for that.

I want to be able to feed build with standard Java config file (in format "key"="value") and then refer to those parameters like every other parameters during the build.

Do you know of an appropriate solution?

like image 375
orshachar Avatar asked May 03 '12 08:05

orshachar


People also ask

How do I get parameters from application properties?

You can use @Value("${property-name}") from the application. properties if your class is annotated with @Configuration or @Component . You can make use of static method to get the value of the key passed as the parameter.

How fetch data from properties file in selenium?

Properties props=new Properties(); To read the file we have to use the Java Filereader and set the path of the properties file. FileReader reader=new FileReader("file path"); Then we have to load the File into the properties using the load method.

How do you get all values from properties file in Java?

Get All Key Values from Properties File Get All Key Values from Properties File in java using the Properties class Available in java. util Package. The Properties class extends the Hashtable class. From Hashtable, Properties class inherits the Method KeySet() which Returns a Set view of the keys Contained in this Map.


2 Answers

Use EnvInject Plugin to read your parameters from a file as environment variables in an Inject Environment Variables build step. The glitch is that then you can't override them easily. One solution would be to use it in conjunction with the Conditional BuildStep Plugin. You can then can define a boolean parameter OVERRIDE that would be false by default. You can then run your Inject build step conditionally only when OVERRIDE is false. When you need to override your parameters with values provided by hand (on in a custom call to run the job) specify the override values and set OVERRIDE to true.

like image 61
malenkiy_scot Avatar answered Sep 23 '22 11:09

malenkiy_scot


I use hudson with ant and set parameters (customer) in my hudson job. This parameter is then the name of a property file that i open with ant as follow:

<loadproperties> srcFile="${project.dir}/build/resources/${customer}.properties"/>
like image 38
enjoy Avatar answered Sep 19 '22 11:09

enjoy