I using groovy script to fetch all Hudson jobs older than 30 days. using below script. I also want to disable all the old jobs as part of this script, can someone suggest how to do this.
below is the script for hudson.
// Set how old the jobs to list should be (in days)
def numDaysBack = 30
def cutOfDate = System.currentTimeMillis() - 1000L * 60 * 60 * 24 * numDaysBack
//Initiallize it to zero
def oldJobsNumber = 0
def size = hudson.model.Hudson.instance.getItems().size()
println "Total Number of Jobs on hudson :" + size
for (i=0;i<size;i++){
def allJob= hudson.model.Hudson.getInstance().getItems().get(i).getAllJobs()
def job =new ArrayList(allJob).get(0)
if (job != null && job .getLastBuild() != null && job.getLastBuild().getTimeInMillis() < cutOfDate) {
println job.getFullName()
oldJobsNumber++
}
}
println oldJobsNumber
The reason I have written the complete code here is because it was on my pending list since long. I am sure you could have figured it out if you had invested some more time on this.