Skip to content

Commit

Permalink
Bug Fix for apache-airflow-providers-jenkins `JenkinsJobTriggerOper…
Browse files Browse the repository at this point in the history
…ator` (#22802)

* bugfix for when polling for the created job, if fail to get job info it should not fail the task, instead it should continue polling until reaches the max allowed polling tries
  • Loading branch information
SasanAhmadi authored Apr 12, 2022
1 parent 069666c commit e5dd6fd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions airflow/providers/jenkins/operators/jenkins_job_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,18 @@ def poll_job_in_queue(self, location: str, jenkins_server: Jenkins) -> int:
# once it will be available in python-jenkins (v > 0.4.15)
self.log.info('Polling jenkins queue at the url %s', location)
while try_count < self.max_try_before_job_appears:
location_answer = jenkins_request_with_headers(
jenkins_server, Request(method='POST', url=location)
)
try:
location_answer = jenkins_request_with_headers(
jenkins_server, Request(method='POST', url=location)
)
# we don't want to fail the operator, this will continue to poll
# until max_try_before_job_appears reached
except (HTTPError, JenkinsException):
self.log.warning('polling failed, retrying', exc_info=True)
try_count += 1
time.sleep(self.sleep_time)
continue

if location_answer is not None:
json_response = json.loads(location_answer['body'])
if (
Expand All @@ -168,8 +177,9 @@ def poll_job_in_queue(self, location: str, jenkins_server: Jenkins) -> int:
return build_number
try_count += 1
time.sleep(self.sleep_time)

raise AirflowException(
"The job hasn't been executed after polling " f"the queue {self.max_try_before_job_appears} times"
f"The job hasn't been executed after polling the queue {self.max_try_before_job_appears} times"
)

def get_hook(self) -> JenkinsHook:
Expand Down

0 comments on commit e5dd6fd

Please sign in to comment.