Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d7b59f

Browse files
martian-ardarhashar
authored andcommitted
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 2aa1a5f which introduced the scenarios. Signed-off-by: Antoine Musso <[email protected]> Change-Id: I1b69adf121ee74e3336ac9bd1d4d55797fb72de5
1 parent 2e389ce commit 0d7b59f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

jenkins/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ def get_running_builds(self):
11491149
executor_number = executor['number']
11501150
build_number = executable['number']
11511151
url = executable['url']
1152-
m = re.match(r'/job/([^/]+)/.*', urlparse(url).path)
1152+
m = re.search(r'/job/([^/]+)/.*', urlparse(url).path)
11531153
job_name = m.group(1)
11541154
builds.append({'name': job_name,
11551155
'number': build_number,

tests/test_build.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def test_with_builds_master(self, nodes_mock, node_info_mock):
259259
"number": 1,
260260
"result": None,
261261
"timestamp": 1442262342729,
262-
"url": "https://localhost/job/test/1/",
262+
"url": self.make_url('job/test/1/'),
263263
"builtOn": "",
264264
"changeSet": {
265265
"items": [],
@@ -293,7 +293,7 @@ def test_with_builds_master(self, nodes_mock, node_info_mock):
293293
'number': 1,
294294
'node': '(master)',
295295
'executor': 1,
296-
'url': 'https://localhost/job/test/1/'}], builds)
296+
'url': self.make_url('job/test/1/')}], builds)
297297

298298
@patch.object(jenkins.Jenkins, 'get_node_info')
299299
@patch.object(jenkins.Jenkins, 'get_nodes')
@@ -338,7 +338,7 @@ def test_with_builds_non_master(self, nodes_mock, node_info_mock):
338338
"number": 15,
339339
"result": None,
340340
"timestamp": 1442262342729,
341-
"url": "https://localhost/job/test/15/",
341+
"url": self.make_url("job/test/15/"),
342342
"builtOn": "",
343343
"changeSet": {
344344
"items": [],
@@ -372,7 +372,7 @@ def test_with_builds_non_master(self, nodes_mock, node_info_mock):
372372
'number': 15,
373373
'node': 'foo-slave',
374374
'executor': 0,
375-
'url': 'https://localhost/job/test/15/'}], builds)
375+
'url': self.make_url('job/test/15/')}], builds)
376376

377377
@patch.object(jenkins.Jenkins, 'get_node_info')
378378
@patch.object(jenkins.Jenkins, 'get_nodes')

0 commit comments

Comments
 (0)