2
votes

Looking for a way how to run the simple command in groovy (using in jenkins) with quotes inside.

My code is:

"grep 'text ' /tmp/test.txt".execute()

I want to grep all lines with text (and space after it).

But as a result I'm always getting grep of "text" only (without the space). Actually groovy for some reason drops my quotes.

2

2 Answers

2
votes

Groovy doesn't handle quotes well. Instead you can use the array form:

['grep', 'text ', '/tmp/test.txt'].execute().text
0
votes

Try the following:

def res = ['grep', 'text ', 'test.txt'].execute( null, new File( '/tmp/' ) ).text