Search through console output of a Jenkins job

Viewed 47124

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?

8 Answers

To search in logs of all jobs:

I enhanced @DaveBacher 's code to be run in the Jenkins script console. Helped me to locate a sporadic error happening in multiple jobs.

NEEDLE = "string_i_am_looking_for"

for (job in Jenkins.instance.getAllItems(Job.class)) {
  for (build in job.builds) {
    def log = build.log
    if (log.contains(NEEDLE)) {
      println "${job.name}: ${build.id}"
    }
  }
}

Just to throw another plugin out there, this blog post pointed me at the TextFinder plugin which allows you to search for text in either a workspace file or the console output, and override the build status as success/failure when the text is found.

The original poster doesn't say what should happen when the text is found, but it was searching for this functionality that brought me here.

To search for a regex pattern in all Jenkins jobs, and print the first matching line:

for (job in Jenkins.instance.items) {
  for (build in job.builds) {
    try {
      def log = build.log
      def match = log =~ "\n(.*${PATTERN}.*)\n"
      if (match) {
        println "Job [${job.name}] - Build [${build.id}]: ${match[0][0]}"
      }
    }
    catch (Exception e) {
      println e
    }
  }
}

For example, searching in my builds for PATTERN = "(TLS|Build).*timeout" I found:

Job [OSP-AWS] - Build [83]: Build timeout: dial tcp [::1]:6443: connect: connection refused

Job [OSP-GCP] - Build [21]: Unable to connect to the server: net/http: TLS handshake timeout

Just use Jenkins std search (top right corner) with keyword "console":

console:"whatever you are looking for"
Related