Injecting more than one properties file into a Jenkins job - jenkins

Right now I'm using EnvInject plugin to insert my environment variables through a properties file into my Jenkins job.
However, now I have a second job which needs the same environment variables as the first job and than some more additional variables which I would like to load via another properties file.
I know, there is a possibility to insert the values via Properties Content Edit field of the EnvInject-plugin, but I would like to keep it in a file, so it can be shared between jobs. But there seems to be no possibility to add a second properties file to EnvInject-plugin.
Is there any way to inject more than one properties file into a job or any other plugin, that could handle my scenario?

There is a simple way to get around the limitation you have.
You should load each file in the Build section, as a build step.
Use the Inject environment variables build step, and load each file you want. You can add multiple files by setting up multiple build steps of this type.
This works well for me on a similar need.

You can use Config File Provider Plugin to config some shell scripts.
You can add multiple files and then execute them.

Related

Is there a way to overwrite a value contained within a config.properties file via Jenkins?

Is there a way to overwrite a value contained within a config.properties file via Jenkins?
I have the following config.properties file contained within my automation framework:
browser=chrome
url=http//www.example.com
If the value of chrome get changed to firefox then all tests will now execute within firefox browser.
I can manually change this value by directly accessing the config.properties file but can the value get altered via jenkins?
I use the Pipeline Utility Steps plugin to read properties files, and it looks like it can write a few other types of files, but not properties files.
It seems to me that you want to make this change in this file so you can run some tests first in one browser, then in another. If this is the case, I think a better way to handle this is to try to get your tests to point to different files. This is a little cleaner, and allows things like parallel execution and when you find that another thing needs to change in the future, you won't be writing so many things to the file in a script, which gets a little error prone.
If you can't make your tests execute against a different properties file, you could have a copy of each file you need, and then copy them to them appropriate filename to execute your tests.
But maybe I made poor assumptions as to your setup here. ;)
Yes.
You can create a build parameter as $browser to accept the value say "firefox" and using sed inside "execute shell", replace the value in config.properties.
Once done, execute your scripts.
This is just overview as you have not posted details about your config.properties file, its location, if you are using Jenkins jobs or jenkinsfile/pipeline etc.

How to configure parameters with time stamp

I have a job ( parameterized build) I am using BUILD_ID as a parameter and I need to add time stamp for the every BUILD_ID.
How to add time-stamp to the parameter.
I need the BUILD_ID value like Test_Build_{time-stamp}.
Kindly help me
There are numerous ways to do this.
Probably your best bet is the Dynamic Parameter Plugin. On the plugin page, one of its main examples does almost exactly what you described.
The Active Choices Plugin allows you to run groovy code to generate your parameter value(s). Here's a screenshot of the plugin setup along with the groovy code:
The EnvInject Plugin allows you to insert environment variables from a properties file as a build step. Using this method you would basically have to have 2 build steps, one to create the properties file and another to read it.
Or using the Groovy Plugin, you can add a groovy script build step to modify the parameter value.
I'm sure there a number of other ways to accomplish this as well.
Install Zen Timestamp plugin and use variable $BUILD_TIMESTAMP

Jenkins manual trigger, how to display configuration variables from SVN on page

I have all my test environment configurations stored in SVN in .properties files. I also have a Jenkins job that can deploy my artifacts to a specific test environment with delivery/build pipeline manual trigger. However, this can create a sense of uncertainty because I am never quite sure what configurations I deploy to the test environment as Jenkins does not automatically show them to you.
I noticed Jenkins offers parameterized builds, and offers you a page which lets you parameterize some values e.g. using some drop-down before triggering the build. My question is , would it be possible to have Jenkins display all the key/value pairs I have defined in my .properties file, and even let me change them? This way I could always review/edit my environment properties before actually making the deployment. Ofcourse, if I make changes then I need to remember to add them to SVN too... Thanks for your input!

Hudson / Jenkins: share parameters between several jobs

I have about 20 jobs using common parameters (user, password), and sometimes the password expires... So I have to change it on all jobs, which is really time consuming (and error prone, I may forget one).
I thought about:
using a kind of magic property file if that exists to have directly lines like KEY, VALUE added into job parameters
adding the same kind of KEY, VALUE pair directly inside build.xml, but where ? And it's really ugly... Maybe with a dedicated XML embedded into the build.xml ?
calling a slave job that would (how ?) push up to the parent one the desired values...
As you can see I'm only starting in Hudson/Jenkins (I'm using Jenkins 1.424.2.2), thanks for your help !
EDIT: I'm not admin of the Jenkins instance, so I cannot have access to global properties...
Go to your Jenkins home and navigate :
Manage Jenkins >
Configure System >
Global properties >
Environment variables > ....
I can think of two approaches:
Use Global properties, found under Manage Jenkins -> Configure system. Here you can define environment variables that should be available to all jobs.
Write a small script that downloads, modifies and posts the job config: http://[jenkinshost]/job/[jobname]/config.xml.
You can read about the api capabilities under http://[jenkinshost]/job/[jobname]/api, here is what it says about reading and changing config.xml:
Fetch/Update config.xml
To programmatically obtain config.xml, hit
[http://[jenkinshost]/job/[jobname]/config.xml]. You can also POST
an updated config.xml to the same URL to programmatically update the
configuration of a job.
I eventually succeeded by:
keeping encrypted credentials in a web page
retrieving them in Hudson thanks to a shell script (wget), decrypt them, and creating a build.properties file in the workspace with lines name=value (in my case ssh.password=...)
This works, because Ant build steps detect this file and pass the variables inside into their context. Thanks to that I could centralize my credentials.

Get result of a build step in Hudson/Jenkins to re-use it in another one

My question may be silly but I've been trying several ways and I still can't do what I want, i.e.:
use the scp target of Ant to target a remote machine and execute
a script there
this script creates a dynamic list of files
get this list of files (only their names) back in Hudson to use it in the next build step (another scp from Ant)
I tried to use environment variables but they are interpreted by Hudson so I'm stuck here...
Globally my question would be: how to get a result from an Ant build step ?
Thanks for your ideas,
Emmanuel
You may find File parameter useful. This allows you to create an input file, pass it to build. You may need to write script/ant script to process the file though.
In the long term you may evaluate a Hudson farm. This will allow to create tasks that span multiple machines , pass results around. (https://wiki.jenkins-ci.org/display/JENKINS/Plugins)
You can get the ID(s) of the job that triggered your job via the API and fetch their status.

Resources