Skip to content

Instantly share code, notes, and snippets.

@vamshisuram
Forked from perja12/delete_artifacts.groovy
Created April 7, 2022 17:44
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 vamshisuram/5ea6e6948126ae9f43b536135097242d to your computer and use it in GitHub Desktop.
Save vamshisuram/5ea6e6948126ae9f43b536135097242d to your computer and use it in GitHub Desktop.
Delete artifacts from Jenkins with Groovy script.
// Delete old artifacts that fills up the disk on the master node.
// Run this from the Jenkins console (Manage Jenkins, Manage Nodes, master, Script Console)
def project = Jenkins.get().getItemByFullName('your-project-id')
def jobs = project.getAllJobs()
def total_size = 0
jobs.each{ job ->
def builds = job.getBuilds()
builds.each{ build ->
def artifacts = build.artifacts
artifacts.each{ artifact ->
total_size += artifact.getFileSize()
println "$artifact, ${artifact.getFileSize()}"
}
build.deleteArtifacts()
}
}
println "Total size: $total_size"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment