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?
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}"
}
}
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|'
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.
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.
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.
来源:https://stackoverflow.com/questions/36188512/search-through-console-output-of-a-jenkins-job