Search through console output of a Jenkins job

user1550159 picture user1550159 · Mar 23, 2016 · Viewed 34.3k times · Source

I have a Jenkins job with 100+ builds. I need to search through all the builds of that job to find builds that have a certain string in the console output. Is there any plugin for that? How do I do that?

Answer

Dave Bacher picture Dave Bacher · Mar 24, 2016

I often use the Jenkins Script Console for tasks like this. The Groovy plugin provides the Script Console, but if you're going to use the Script Console for periodic maintenance, you'll also want the Scriptler plugin which allows you to manage the scripts that you run.

From Manage Jenkins -> Script Console, you can write a groovy script that iterates through the job's builds looking for the matching string:

JOB_NAME = "My Job"
BUILD_STRING = "Hello, world"

def job = Jenkins.instance.items.find { it.name == JOB_NAME }
for (build in job.builds) {
  def log = build.log
  if (log.contains(BUILD_STRING)) {
    println "${job.name}: ${build.id}"
  }
}