Created
November 19, 2015 13:19
-
-
Save tizki/3a1c28b26c99c52cf93a to your computer and use it in GitHub Desktop.
Jenkins groovy script - get artifacts from build by name and time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def numOfMonths = 4 | |
Calendar calendar = Calendar.getInstance(); | |
calendar.add( Calendar.DAY_OF_MONTH, numOfMonths * -1 ); | |
def filterTime = calendar.getTime() | |
def jobName = "MaaS-Job-Tests-Integration-Server-release-3.3" | |
def jen = Jenkins.getInstance(); | |
def jobToClean = jen.getItem(jobName); | |
def buildsList = jobToClean.getBuilds() | |
def filterClosure = { b -> | |
b.timestamp?.time?.before(filterTime) | |
} | |
def printClosure = { | |
println("${it.getArtifactManager()?.root().exists()}") | |
} | |
def deleteClosure = { | |
println("Deleting artifacts from ${it}") | |
it.deleteArtifacts() | |
} | |
buildsList.findAll(filterClosure).each(printClosure) | |
//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