pycontribs / jenkinsapi

A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
http://pypi.python.org/pypi/jenkinsapi
MIT License
857 stars 483 forks source link

Invoking job build with `block=True` fails on network errors #825

Open cedrak opened 1 year ago

cedrak commented 1 year ago
ISSUE TYPE
Jenkinsapi VERSION

0.3.11

Jenkins VERSION

2.176.3

SUMMARY

Blocking for build completion breaks when networking is unreliable.

EXPECTED RESULTS

I would expect that block would be (at least to some extent) resilient to network errors like in the case of queue.block_until_building.

ACTUAL RESULTS

Blocking for build completion breaks when Jenkins instance will respond with one non-200 response.

USEFUL INFORMATION

How to reproduce:

  1. Make connection to Jenkins
  2. Invoke job with block=True
  3. During building on Jenkins receive 502 response from server
16:11:16 Traceback (most recent call last):
(...)
16:11:16   File "/home/jenkins/workspace/***.py", line 105, in build
16:11:16     queue_item = job.invoke(build_params=params, block=True)
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/jenkinsapi/job.py", line 238, in invoke
16:11:16     qi.block_until_complete(delay=delay)
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/jenkinsapi/queue.py", line 142, in block_until_complete
16:11:16     return build.block_until_complete(delay=delay)
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/jenkinsapi/build.py", line 417, in block_until_complete
16:11:16     while self.is_running():
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/jenkinsapi/build.py", line 399, in is_running
16:11:16     data = self.poll(tree='building')
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/jenkinsapi/jenkinsbase.py", line 60, in poll
16:11:16     data = self._poll(tree=tree)
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/jenkinsapi/build.py", line 63, in _poll
16:11:16     return self.get_data(url, params={'depth': self.depth}, tree=tree)
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/jenkinsapi/jenkinsbase.py", line 84, in get_data
16:11:16     response.raise_for_status()
16:11:16   File "/tmp/venv/lib/python3.8/site-packages/requests/models.py", line 1021, in raise_for_status
16:11:16     raise HTTPError(http_error_msg, response=self)
16:11:16 requests.exceptions.HTTPError: 502 Server Error: Bad Gateway for url:

I could make PR, but I would need some assistance, to confirm if my solution proposition is correct.