Forked from nextrevision/deleteJenkinsJobs.groovy
Last active
February 7, 2018 12:00
-
-
Save miguelfito/a8a1ad07e16d1789c6aaf65eeea42352 to your computer and use it in GitHub Desktop.
[Jenkins] Groovy script to delete all jenkins jobs that match a regex pattern
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
import jenkins.model.* | |
i = 1 | |
def matchedJobs = Jenkins.instance.items.findAll { job -> | |
job.name =~ /my_regex_here/ | |
} | |
matchedJobs.each { job -> | |
println i++ + " >> This job will be deleted: " + job.name | |
//job.delete() | |
} |
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
import jenkins.* | |
import jenkins.model.* | |
import hudson.* | |
import hudson.model.* | |
import hudson.scm.* | |
import hudson.tasks.* | |
import com.cloudbees.hudson.plugins.folder.* | |
i = 1 | |
jen = Jenkins.instance | |
jen.getItems().each{ | |
if(it instanceof Folder){ | |
processFolder(it) | |
}else{ | |
processJob(it) | |
} | |
} | |
void processJob(Item job){ | |
if (job.name ==~ /.*None$/){ | |
println i++ + " >> This job will be deleted: " + job.name | |
//job.delete() | |
} | |
} | |
void processFolder(Item folder){ | |
folder.getItems().each{ | |
if(it instanceof Folder){ | |
processFolder(it) | |
}else{ | |
processJob(it) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment