Skip to content

Instantly share code, notes, and snippets.

@or-shachar
Created December 25, 2017 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save or-shachar/4835ad5990af0c34d7ec51143d145c2c to your computer and use it in GitHub Desktop.
Save or-shachar/4835ad5990af0c34d7ec51143d145c2c to your computer and use it in GitHub Desktop.
/*
Jenkins - If found "lookup_string" in last run of a job - triggers it again with the same parameters
*/
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
if (lastRun == null) //skip jobs that never ran
continue
lastBuildLog = lastRun.log
if (lastBuildLog.contains(lookup_string)){
println job.fullName + " " + instance.rootUrl + lastRun.url
params = lastRun.getActions(hudson.model.ParametersAction)
Jenkins.instance.queue.schedule2(job,3,params)
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