Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read properties file from Jenkins 2.0 pipeline script

I am attempting to write a pipeline script to use with Jenkins 2.0 to replicate our existing build. This original build used the envInject plugin to read a Java properties file, but I can't see how to do this from the pipeline Groovy script. I have Googled and found the following, but it doesn't work (FileNotFoundException):

Properties props = new Properties() File propsFile = new File('./Builder/project.properties') props.load(propsFile.newDataInputStream()) 

Thanks!

like image 840
Pete Singleton Avatar asked Sep 21 '16 14:09

Pete Singleton


People also ask

How do you access Jenkins parameters in a pipeline script?

Access Parameters Inside Pipeline Stages You just have to use params. [NAME] in places where you need to substitute the parameter. Here is an example of a stage that will be executed based on the condition that we get from the choice parameter.

How use Jenkins properties file?

Create a Managed file for properties Add build step: select provide configuration files as a build step and select created ABE_properties managed file. Notice that we have selected replace tokens option and set the target location of property file.

How do I read a text file in Jenkins pipeline?

In the first stage we create a variable called data that holds some text and the we use the writeFile function to write it out to a file. Then we execute ls as an external program using sh. In the second stage we use the readFile function to read in the content of the file.


1 Answers

I just fought with this yesterday and today. I wish the availability of this was easier to find.

Grab the 'Pipeline Utility Steps' plugin.

Use the readProperties step.

 def props = readProperties  file: 'dir/my.properties' 

One word of warning - what I expected to be booleans in the properties files were treated as strings.

like image 118
Mike Kingsbury Avatar answered Sep 23 '22 02:09

Mike Kingsbury