diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 3e7a497e9..2eae81859 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -144,6 +144,13 @@ class Jenkins(object): logger.info("Deleting jenkins job {0}".format(job_name)) self.jenkins.delete_job(job_name) + def delete_all_jobs(self): + # execute a groovy script to delete all jobs is much faster than + # using the doDelete REST endpoint to delete one job at a time. + script = ('for(job in jenkins.model.Jenkins.theInstance.getProjects())' + ' { job.delete(); }') + self.jenkins.run_script(script) + def get_plugins_info(self): """ Return a list of plugin_info dicts, one for each plugin on the Jenkins instance. @@ -279,8 +286,7 @@ class Builder(object): def delete_all_jobs(self): jobs = self.jenkins.get_jobs() logger.info("Number of jobs to delete: %d", len(jobs)) - for job in jobs: - self.delete_job(job['name']) + self.jenkins.delete_all_jobs() def update_job(self, input_fn, jobs_glob=None, output=None): self.load_files(input_fn) diff --git a/requirements.txt b/requirements.txt index 5cc74b920..b4be8c00c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ ordereddict six>=1.5.2 PyYAML -python-jenkins>=0.4.1 +python-jenkins>=0.4.8 pbr>=0.8.2,<2.0