summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jenkins_jobs/builder.py13
-rw-r--r--tests/jenkins_manager/test_manager.py2
2 files changed, 9 insertions, 6 deletions
diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py
index abed1d40..d72cf201 100644
--- a/jenkins_jobs/builder.py
+++ b/jenkins_jobs/builder.py
@@ -122,12 +122,11 @@ class JenkinsManager(object):
self._job_format(job_name)))
self.jenkins.create_job(job_name, xml)
- def is_job(self, job_name):
- # first use cache
- if job_name in self.job_list:
- return True
+ def is_job(self, job_name, use_cache=True):
+ if use_cache:
+ if job_name in self.job_list:
+ return True
- # if not exists, use jenkins
return self.jenkins.job_exists(job_name)
def get_job_md5(self, job_name):
@@ -190,7 +189,9 @@ class JenkinsManager(object):
keep = []
for job in jobs:
# python-jenkins stores the folder and name as 'fullname'
- if job['fullname'] not in keep:
+ # Check if the job was deleted when his parent folder was deleted
+ if job['fullname'] not in keep and \
+ self.is_job(job['fullname'], use_cache=False):
if self.is_managed(job['fullname']):
logger.info("Removing obsolete jenkins job {0}"
.format(job['fullname']))
diff --git a/tests/jenkins_manager/test_manager.py b/tests/jenkins_manager/test_manager.py
index cc8e3d41..ba579d15 100644
--- a/tests/jenkins_manager/test_manager.py
+++ b/tests/jenkins_manager/test_manager.py
@@ -60,11 +60,13 @@ class TestCaseTestJenkinsManager(base.BaseTestCase):
with mock.patch.multiple('jenkins_jobs.builder.JenkinsManager',
get_jobs=mock.DEFAULT,
+ is_job=mock.DEFAULT,
is_managed=mock.DEFAULT,
delete_job=mock.DEFAULT) as patches:
patches['get_jobs'].return_value = [{'fullname': 'job1'},
{'fullname': 'job2'}]
patches['is_managed'].side_effect = [True, True]
+ patches['is_job'].side_effect = [True, True]
self.builder.delete_old_managed()
self.assertEqual(patches['delete_job'].call_count, 2)