5

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 ??

Naveen Kumar
  • 2,570
  • 3
  • 20
  • 22

1 Answers1

7

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()
    }
}
Vadim Landa
  • 2,784
  • 5
  • 23
  • 33
  • 1
    The if/else is the wrong way around. `Data_jobs_server` will never be disabled, because it gets **deleted**! – Christopher Orr May 30 '15 at 16:44
  • To be sure to get jobs in subfolders use for (job in Jenkins.instance.getAllItems(Job.class)) – MKesper Nov 28 '18 at 13:08
  • I am the admin but getting error "hudson.security.AccessDeniedException3: nageswar.k. is missing the Job/Delete permission – Paul Jun 16 '21 at 18:53