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
1,404 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,890 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,070 points
6,802 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
27 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
150 views
0 votes
1 answer
0 votes
1 answer
+2 votes
5 answers