Skip to main content

Posts

Showing posts with the label delete jenkins job

How to delete jobs in Jenkins using Groovy Script

Background I am working on a project that depends using Jenkins with vast number of jobs dynamically created. We had a use-case where the Jenkins job[s] needs to be deleted. Based on analysis of the REST API offered by Jenkins, I was not able to find the API to delete multiple jobs. We can delete every job through the API, however that would be very chatty, had the user opted to delete more than 2 or 3 jobs at a time. In order to improve the performance, I decided to build a Jenkins job that does the job of deleting multiple jobs Job Selection in Jenkins In Jenkins, we might be having jobs at the root level or contained within folders and in case of having then under folders, we might be having the multiple folders nested. Jenkins has a name for a job which is just name of the job and a fullName that is the full jenkins path inclusive of the folders that contain this job from the jenkins root. In order to select a suitable collection of jobs, we must prefer to use the fullName based na