Jenkins properties file

+5 votes

How to change values in .properties file and run a build using the values in jenkins?

Mar 27, 2018 in Jenkins by Atul
• 10,240 points
28,305 views

5 answers to this question.

+2 votes

You can try to use the EnvInject Plugin for Jenkins which allows to inject environment variables into build process, and modify your .bat file to use them instead of reading values from the properties file.

Here are some of the plugin's usecases/features:

To remove inherited environment variables (PATH, ANT_HOME, ...) at node level (master/slave), available by default for a job run.
To inject variables in the first step of the job (before the SCM checkout)
To inject variables based on user parameter values
To execute an initialization script before a SCM checkout.
To execute an initialization script after a SCM checkout
To inject variables as a build step obtained from a file filled in by a previous build step
To know environment variables used for a build
To inject build cause as environment variable for a build
To inject environment variables from the evaluation of a Groovy script (powered by Script Security Plugin)
To export environment variables as a metadata in your binary repository

answered Mar 27, 2018 by DragonLord999
• 8,450 points

edited Oct 16, 2018 by Kalgi
@Dragonlord, what is the difference between .bat file and a .properties file?
+2 votes

Follow these steps:

1. Install ‘EnvInject’ plug-in in the Jenkins CI tool.

2. After installing ‘EnvInject’ plug-in, you will see ‘Inject environment variables’ option under ‘Add Build Step’.

3. Configure the plug-in with Jenkins job by clicking on ‘Inject environment variables’ option.

4. You will see two fields: ‘Properties File Path’ and ‘Properties Content’ field after adding ‘Inject environment variables’.

5. In ‘Properties File Path’ field, provide the path of the properties file, i.e. where it exists in the Automation project and in ‘Properties Content’ field, provide all the information that you want to change in the run time

6. Now, run the Jenkins’s job to set all the ‘Properties Content’ field data into environment variable of target Virtual machine temporarily.

7. Get the properties data from the System environment variables and update the properties file.  This can be done by configuring the build.xml file

answered Aug 2, 2018 by lina
• 8,220 points
If build.xml file is already exist, where can i find it? if i want to create newly please let me know how to create.
0 votes

To change the property values, open the output stream and store properties after you have closed the input stream.

FileInputStream in = new FileInputStream("First.properties");
Properties props = new Properties();
props.load(in);
in.close();

FileOutputStream out = new FileOutputStream("First.properties");
props.setProperty("country", "america");
props.store(out, null);
out.close();
answered Oct 16, 2018 by Kalgi
• 52,350 points
0 votes

You can use the EnvInject plugin. This plugin makes it possible to have an isolated environment for your jobs.

answered Dec 6, 2018 by Sai
0 votes

Use cases of the EnvInject plug-in:

  • To remove inherited environment variables (PATH, ANT_HOME, ...) at node level (master/slave), available by default for a job run.
  • To inject variables in the first step of the job (before the SCM checkout)
  • To inject variables based on user parameter values
  • To execute an initialization script before a SCM checkout.
  • To execute an initialization script after a SCM checkout
  • To inject variables as a build step obtained from a file filled in by a previous build step
  • To know environment variables used for a build
  • To inject build cause as environment variable for a build
  • To inject environment variables from the evaluation of a Groovy script 
  • To export environment variables as a metadata in your binary repository
answered Dec 6, 2018 by Kunal

Related Questions In Jenkins

0 votes
0 answers
0 votes
2 answers
+1 vote
3 answers

Rename jobs from jenkins file

Go to the Configure screen and edit the Project name field ...READ MORE

answered Oct 25, 2018 in Jenkins by Laila
4,747 views
0 votes
2 answers
+1 vote
1 answer
+1 vote
3 answers

"No such file pom.xml" error in Jenkins

Can you please che ck the location ...READ MORE

answered May 16, 2019 in Jenkins by Samir
21,800 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,035 views
+2 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP