Search code examples
jenkinsjobs

Delete jenkins jobs having the matching pattern


How to delete jobs on jenkins having the prefix "Data_jobs_" ? and How to disable all jobs having prefix "Data_jobs_server" ?

Anyone know how to do this by going /script page ??


Solution

  • The following should work:

    for (job in jenkins.model.Jenkins.theInstance.getProjects()) {
        if (job.name.startsWith("Data_jobs_"))  {
            job.delete()
        }
        else if (job.name.startsWith("Data_jobs_server"))  {
            job.disable()
        }
    }