且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

搜索Jenkins作业的控制台输出

更新时间:2023-12-05 13:51:46

我经常使用 Jenkins脚本控制台,用于执行此类任务. Groovy插件提供了脚本控制台,但是如果您要使用脚本控制台进行定期维护,您还需要 Scriptler插件,使您可以管理所运行的脚本.

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.

Manage Jenkins -> 脚本控制台中,您可以编写一个普通的脚本,该脚本遍历作业的构建以寻找匹配的字符串:

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