Vidisha
Vidisha

Reputation: 63

Want to delete Jenkins jobs

I have around 600+ Jenkins jobs which needs to be removed since those are no longer being used. Could any one suggest what are the ways we can remove those jobs easily?

Upvotes: 2

Views: 5638

Answers (2)

not2savvy
not2savvy

Reputation: 4243

While the accepted answer is much more elegant, for the sake of completeness, I'd like to add the following alternative approach:

If you have access to the master node, go to the jobs folder within the Jenkins home directory and remove the folders named like the jobs you want to get rid of. Afterwards, restart Jenkins so it refreshes its job list.

Upvotes: 0

fredericrous
fredericrous

Reputation: 3028

Go to Jenkins Console (https://<url>/script) and execute a groovy script like this one

import jenkins.model.*

def matchedJobs = Jenkins.instance.items.findAll { job ->
    job.name =~ /my_regex_here/
}

matchedJobs.each { job ->
    println job.name
    job.delete()
}

https://gist.github.com/nextrevision/d11b2df4e8b229c6855b

If the jobs are inside folders, look at the script shared by pjlbyrne

Upvotes: 4

Related Questions