Skip to content

Instantly share code, notes, and snippets.

@or-shachar
Created December 7, 2017 13:18
Show Gist options
  • Save or-shachar/5b227344e0f5cc2472ff025b9dfb5f5f to your computer and use it in GitHub Desktop.
Save or-shachar/5b227344e0f5cc2472ff025b9dfb5f5f to your computer and use it in GitHub Desktop.
Count all jobs of certain name that has certain string in their last run
job_name="some-job" //I have multiple jobs with the same simple name under multiple folders
lookup_string="something inside the log" // the line we want to look for
instance = Jenkins.instance
def jobs = instance.allItems.findAll{it.name==job_name}
count = 0
for (job in jobs){
lastRun = job.lastCompletedBuild
lastBuildLog = lastRun.log
if (lastBuildLog.contains(lookup_string)){
println job.fullName + " " + instance.rootUrl + lastRun.url
count = count + 1
}
}
println "${count} out of ${jobs.size}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment