Created
July 30, 2018 11:25
-
-
Save perja12/5bd255e45b1b2395dfd723500e93a77b to your computer and use it in GitHub Desktop.
Delete artifacts from Jenkins with Groovy script.
This file contains 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
// 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