Search through console output of a Jenkins job

╄→尐↘猪︶ㄣ 提交于 2019-12-21 07:57:45

问题


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?


回答1:


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}"
  }
}



回答2:


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|'



回答3:


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.




回答4:


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.




回答5:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!