Print the line if it contains a specific string by using groovy.

0 votes

I am having a Jenkins log file and I am trying to print those lines which are having string "FOUND" in it.

How do I write the code for it in Groovy as I am new to it? Can anyone help me with this?

Thanks.

Apr 27, 2018 in Jenkins by Atul
• 10,240 points
787 views

1 answer to this question.

0 votes

You can try the code written below:

def lines = new File('/tmp/test123.txt').readLines()
def result = lines.findAll { it.contains('FOUND') }
println result*.toString()

I hope that it will resolve your query. 
answered Apr 27, 2018 by shubham
• 6,870 points

Related Questions In Jenkins

+1 vote
1 answer
+4 votes
7 answers

How to set the pipeline name and description for a Jenkinsfile?

You can rename pipeline jobs in jenkins ...READ MORE

answered Oct 11, 2018 in Jenkins by Hannah
• 14,080 points
5,402 views
0 votes
1 answer

Allow starting a new pipeline run from the delivery pipeline view

Yes you can. Go to edit view on ...READ MORE

answered Jul 10, 2018 in Jenkins by Kalgi
• 2,620 points
21 views
+1 vote
3 answers
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer
+2 votes
5 answers