jenkinsjenkins-pipelinedevopsjenkins-groovyjenkins-job-dsl

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?


Solution

  • 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