Skip to content

Instantly share code, notes, and snippets.

@tizki
Last active November 19, 2015 13:47
Show Gist options
  • Save tizki/6088f05ec62fff745cc6 to your computer and use it in GitHub Desktop.
Save tizki/6088f05ec62fff745cc6 to your computer and use it in GitHub Desktop.
Jenkins groovy script - print enabled old jobs with filter
def numOfMonths = 4
Calendar calendar = Calendar.getInstance();
calendar.add( Calendar.MONTH, numOfMonths * -1 );
def threeMonthsAgo = calendar.getTime()
def filterClosure = { job -> ((job.getLastBuild()?.timestamp?.time?.before(threeMonthsAgo) && job.getLastBuild() != null)
&& job.name.toLowerCase().contains('-Branch-'.toLowerCase()) && job.name.toLowerCase().startsWith('MaaS'.toLowerCase())
&& !job.name.toLowerCase().contains('Infra'.toLowerCase()) && !job.isDisabled() ) }
def printClosure = { job ->
println("${job.name}")
}
println ("Builds that run for more than half an hour:")
[hudson.model.FreeStyleProject.class, com.tikal.jenkins.plugins.multijob.MultiJobProject.class, hudson.matrix.MatrixProject.class]
.each { className ->
def foundJobs = jenkins.model.Jenkins.instance.getAllItems(className).findAll(filterClosure).each(printClosure)};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment