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?


Apr 27, 2018 in Jenkins by Atul
• 10,200 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,480 points

Related Questions In Jenkins

+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
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
+1 vote
3 answers
+1 vote
4 answers
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer
+2 votes
5 answers

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.