How to read string from file using Groovy in QuickBuild

2k views Asked by At

I am new to QuickBuild.

I have a lot of different versions stored in text files.
To start the build process, I need to retrieve the versions from the text files and pass them to a shell script.

My question is: How do I read the contents of a file using the QuickBuild environment?
I know that it supports Groovy, MVEL and OGNL languages but I'm not familiar with any of them.

Thanks in advance.

2

There are 2 answers

0
Cyril On

I found the solution :)

${groovy: str = new java.io.File("[PATH_TO]/file.txt").text}

or

${groovy: str = new java.io.File("[PATH_TO]/file.txt").text
str.split("[\\r\\n]")[0] } 

to read the first line only.

Thanks to me :)

0
Dónal On

A slightly shorter version for reading only the first line (which doesn't make any assumption about the EOL character):

${groovy: str = new File("[PATH_TO]/file.txt").readLines()[0] }