How to read a properties file from the Jenkins 2.0 script pipeline

I am trying to write a pipeline script for use with Jenkins 2.0 to replicate our existing assembly. This original assembly used the envInject plugin to read the Java properties file, but I don’t see how to do this from the Groovy script pipeline. I have Googled and found the following, but it does not work (FileNotFoundException):

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

Thanks!

+5
source share
3 answers

I just fought it yesterday and today. I wish it was easier to find.

Take the Pipes Steps plugin. "

Use the readProperties step.

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

One word of warning is that I was expecting to be boolean in property files, treated as strings.

+16
source

I tried and below works fine:

 test.properties Monday=abcdef Tuesday=kfgh def props = readProperties file:'/var/lib/jenkins/jobs/abc/test.properties' def Var1= props['Monday'] def Var2= props['Tuesday'] echo "Var1=${Var1}" echo "Var2=${Var2}" 
+2
source

i could not figure out how to interpolate plain text from readProperties, so I just made a workaround for expanding the variable.

 def props = readProperties file: 'dir/my.properties' def release = expand_property(props['RELEASE']) def expand_property(property) { def info node("anyUnixNode") { info = sh(script: "echo $property", returnStdout: true) } info = info.trim() return info } 
0
source

All Articles