Cyril
Cyril

Reputation: 159

How to read string from file using Groovy in QuickBuild

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.

Upvotes: 0

Views: 2105

Answers (2)

Dónal
Dónal

Reputation: 187537

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] }

Upvotes: 0

Cyril
Cyril

Reputation: 159

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 :)

Upvotes: 1

Related Questions