get_running_builds failed when server has a path

When the server has an URL path such as http://example.org/ci/, the
get_running_builds() would fail to extract the job name from the
executor informations.  It most probably fails when using CloudBees
folder as well.

Relax the regex used to detect the job name by changing match() with
search().

Update JenkinsListRunningBuildsTest so it craft the URLs based on the
test scenario (make_url) instead of hardcoding them.  That would have
caught the bug. See 2aa1a5f1 which introduced the scenarios.

Signed-off-by: Antoine Musso <hashar@free.fr>
Change-Id: I1b69adf121ee74e3336ac9bd1d4d55797fb72de5
This commit is contained in:
Ardar Martian 2016-08-10 09:26:47 +00:00 committed by Antoine Musso
parent 2e389ce44b
commit 0d7b59f5d2
2 changed files with 5 additions and 5 deletions

View File

@ -1149,7 +1149,7 @@ class Jenkins(object):
executor_number = executor['number']
build_number = executable['number']
url = executable['url']
m = re.match(r'/job/([^/]+)/.*', urlparse(url).path)
m = re.search(r'/job/([^/]+)/.*', urlparse(url).path)
job_name = m.group(1)
builds.append({'name': job_name,
'number': build_number,

View File

@ -259,7 +259,7 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase):
"number": 1,
"result": None,
"timestamp": 1442262342729,
"url": "https://localhost/job/test/1/",
"url": self.make_url('job/test/1/'),
"builtOn": "",
"changeSet": {
"items": [],
@ -293,7 +293,7 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase):
'number': 1,
'node': '(master)',
'executor': 1,
'url': 'https://localhost/job/test/1/'}], builds)
'url': self.make_url('job/test/1/')}], builds)
@patch.object(jenkins.Jenkins, 'get_node_info')
@patch.object(jenkins.Jenkins, 'get_nodes')
@ -338,7 +338,7 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase):
"number": 15,
"result": None,
"timestamp": 1442262342729,
"url": "https://localhost/job/test/15/",
"url": self.make_url("job/test/15/"),
"builtOn": "",
"changeSet": {
"items": [],
@ -372,7 +372,7 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase):
'number': 15,
'node': 'foo-slave',
'executor': 0,
'url': 'https://localhost/job/test/15/'}], builds)
'url': self.make_url('job/test/15/')}], builds)
@patch.object(jenkins.Jenkins, 'get_node_info')
@patch.object(jenkins.Jenkins, 'get_nodes')