Reputation: 1267
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?
Upvotes: 23
Views: 55143
Reputation: 16981
To search for a regular expression text in console output of all Jenkins builds, run the following script in https://{jenkins url}/manage/script
. It will print the job and build number + The first matching line found:
def regex="any text or regular expression"
for (job in Jenkins.instance.items) {
for (build in job.builds) {
try {
def log = build.log
def match = log =~ "\n(.*${regex}.*)\n"
if (match) {
println "Job [${job.name}] - Build [${build.id}]: ${match[0][0]}"
}
}
catch (Exception e) {
println e
}
}
}
For example, searching in my builds with regex = "(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
Upvotes: -1
Reputation: 7
Just use Jenkins std search (top right corner) with keyword "console":
console:"whatever you are looking for"
Upvotes: -2
Reputation: 706
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}"
}
}
}
Upvotes: 6
Reputation: 3379
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.
Upvotes: 1
Reputation: 1267
Thanks everyone for your valuable solutions. After a bit of additional research i found that there is a plugin in Jenkins to do this.
https://wiki.jenkins-ci.org/display/JENKINS/Lucene-Search
This will save the console output results and users can do search in search box.
Upvotes: 3
Reputation: 15972
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}"
}
}
Upvotes: 24
Reputation: 9075
There is the Log Parser Plugin
highlighting lines of interest in the log (errors, warnings,information)
dividing the log into sections displaying a summary of number of errors, warnings and information lines within the log and its sections.
linking the summary of errors and warnings into the context of the full log, making it easy to find a line of interest in the log
showing a summary of errors and warnings on the build page
If it is old logs then @jil has the answer assuming you are on Linux.
Upvotes: 1
Reputation: 2691
If there is no additional requirements I would do it simply in the shell, e.g.:
find $JENKINS_HOME/jobs/haystack -name log -exec grep -l needle {} \; \
| sed 's|.*/\(.*\)/log|\1|'
Upvotes: 11