Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
How to extract only a certain text from a file

so I have a file called "versions.properties", which looks like this-

#ccsmp build version information
#Tue, 12 Apr 2022 15:32:37 -0400
branch.type=feature
cscsmp.svn.branch=branches/features/javarto_maven
ivy.cache.dir.name=${svn.branch}
jrto.version=${jrto.version.major}.${jrto.version.minor}.${jrto.version.maintenance}
jrto.version.build=26856
jrto.version.maintenance=0
jrto.version.major=0
jrto.version.minor=0
lib.version=1.5
openvms_pass=xyz
openvms_server=xyz
openvms_user=loadxyz
svn.branch=branches/features/CRE-442
svn.branchurl=${svn.rooturl}/${svn.branch}
svn.password=xyz
svn.rooturl=svn\://xyz-repo/svn/ccsmp
svn.tagurl=${svn.rooturl}/tags
svn.username=xyz
version.build=846
version.date=2022/04/12 15\:32
version.maintenance=0
version.major=1
version.minor=37
version.release=${version.major}.${version.minor}.${version.maintenance}.${version.build}

I am trying to read this file and then by using the values of version.major, version.minor, version.maintenance, version.build

I want to feed these values into following-

def SVN_TAG=ccsmp_v_${version.major}.${version.minor}.${version.maintenance}.${version.build}

So when I do println ${SVN_TAG}

It outputs -

SVN_TAG=ccsmp_v_1.37.0.846

Is there any way to do this? Any suggestions are highly appreciated

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

def p = readProperties file: 'versions.properties'

def SVN_TAG="ccsmp_v_${p.version.major}.${p.version.minor}.${p.version.maintenance}.${p.version.build}"

https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readproperties-read-properties-from-files-in-the-workspace-or-text

If you don't have readProperties

//declare function with non cps
@NonCPS
def toProperties(String s){
  p = new Properties()
  p.load( new StringReader(s) )
  return p
}


def p = readFile 'versions.properties'
p = toProperties(p)
def SVN_TAG="ccsmp_v_${p.'version.major'}.${p.'version.minor'}..."

or another option with parsing each line

@NonCPS
def toProperties(String s){
  s.readLines().collect{it.split('=')}.findAll{it.size()==2}.collectEntries()
}

//the rest is the same as above
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!