python-jenkins-developers team mailing list archive
-
python-jenkins-developers team
-
Mailing list archive
-
Message #00397
[Bug 1650669] [NEW] Jenkins.get_running_builds() Not Working -- Fixed it for you guys
Public bug reported:
There was a bug in the get_running_builds(). The regular expression was
not functioning properly and you were looking for m.group(1) instead of
m.group(0)...
Here is what the final code I wrote looks like.
Now it works perfectly
I put comments beside what I modified
def get_running_builds(self):
'''Return list of running builds.
Each build is a dict with keys 'name', 'number', 'url', 'node',
and 'executor'.
:returns: List of builds,
``[ { str: str, str: int, str:str, str: str, str: int} ]``
Example::
>>> builds = server.get_running_builds()
>>> print(builds)
[{'node': 'foo-slave', 'url': 'https://localhost/job/test/15/',
'executor': 0, 'name': 'test', 'number': 15}]
'''
builds = []
nodes = self.get_nodes()
for node in nodes:
# the name returned is not the name to lookup when
# dealing with master :/
if node['name'] == 'master':
node_name = '(master)'
else:
node_name = node['name']
try:
info = self.get_node_info(node_name, depth=2)
except JenkinsException as e:
# Jenkins may 500 on depth >0. If the node info comes back
# at depth 0 treat it as a node not running any jobs.
if ('[500]' in str(e) and
self.get_node_info(node_name, depth=0)):
continue
else:
raise
for executor in info['executors']:
executable = executor['currentExecutable']
if executable:
executor_number = executor['number']
build_number = executable['number']
url = executable['url']
m = re.match(r'.*/job/.*', urlparse(url).path) # --> Changed this
job_name = m.group(0) # --> Changed this
builds.append({'name': job_name,
'number': build_number,
'url': url,
'node': node_name,
'executor': executor_number})
return builds
** Affects: python-jenkins
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Python
Jenkins Developers, which is subscribed to Python Jenkins.
https://bugs.launchpad.net/bugs/1650669
Title:
Jenkins.get_running_builds() Not Working -- Fixed it for you guys
Status in Python Jenkins:
New
Bug description:
There was a bug in the get_running_builds(). The regular expression
was not functioning properly and you were looking for m.group(1)
instead of m.group(0)...
Here is what the final code I wrote looks like.
Now it works perfectly
I put comments beside what I modified
def get_running_builds(self):
'''Return list of running builds.
Each build is a dict with keys 'name', 'number', 'url', 'node',
and 'executor'.
:returns: List of builds,
``[ { str: str, str: int, str:str, str: str, str: int} ]``
Example::
>>> builds = server.get_running_builds()
>>> print(builds)
[{'node': 'foo-slave', 'url': 'https://localhost/job/test/15/',
'executor': 0, 'name': 'test', 'number': 15}]
'''
builds = []
nodes = self.get_nodes()
for node in nodes:
# the name returned is not the name to lookup when
# dealing with master :/
if node['name'] == 'master':
node_name = '(master)'
else:
node_name = node['name']
try:
info = self.get_node_info(node_name, depth=2)
except JenkinsException as e:
# Jenkins may 500 on depth >0. If the node info comes back
# at depth 0 treat it as a node not running any jobs.
if ('[500]' in str(e) and
self.get_node_info(node_name, depth=0)):
continue
else:
raise
for executor in info['executors']:
executable = executor['currentExecutable']
if executable:
executor_number = executor['number']
build_number = executable['number']
url = executable['url']
m = re.match(r'.*/job/.*', urlparse(url).path) # --> Changed this
job_name = m.group(0) # --> Changed this
builds.append({'name': job_name,
'number': build_number,
'url': url,
'node': node_name,
'executor': executor_number})
return builds
To manage notifications about this bug go to:
https://bugs.launchpad.net/python-jenkins/+bug/1650669/+subscriptions
Follow ups