eladkal commented on a change in pull request #22421:
URL: https://github.com/apache/airflow/pull/22421#discussion_r832548234



##########
File path: airflow/providers/jenkins/hooks/jenkins.py
##########
@@ -46,3 +47,24 @@ def __init__(self, conn_id: str = default_conn_name) -> None:
     def get_jenkins_server(self) -> jenkins.Jenkins:
         """Get jenkins server"""
         return self.jenkins_server
+
+    def get_build_building_state(self, job_name: str, build_number: int) -> 
bool:
+        """Get build building state"""
+        try:
+            if not build_number:
+                self.log.info(f"Build number not specified, getting latest 
build info from Jenkins")
+                job_info = self.jenkins_server.get_job_info(self.job_name)
+                build_number_to_check = job_info['lastBuild']['number']
+            else:
+                build_number_to_check = self.build_number

Review comment:
       There is no `self.build_number` in the hook. I guess this is a mistake?

##########
File path: airflow/providers/jenkins/hooks/jenkins.py
##########
@@ -46,3 +47,24 @@ def __init__(self, conn_id: str = default_conn_name) -> None:
     def get_jenkins_server(self) -> jenkins.Jenkins:
         """Get jenkins server"""
         return self.jenkins_server
+
+    def get_build_building_state(self, job_name: str, build_number: int) -> 
bool:

Review comment:
       can you add unit test to the hook function?

##########
File path: airflow/providers/jenkins/hooks/jenkins.py
##########
@@ -46,3 +47,24 @@ def __init__(self, conn_id: str = default_conn_name) -> None:
     def get_jenkins_server(self) -> jenkins.Jenkins:
         """Get jenkins server"""
         return self.jenkins_server
+
+    def get_build_building_state(self, job_name: str, build_number: int) -> 
bool:
+        """Get build building state"""
+        try:
+            if not build_number:
+                self.log.info(f"Build number not specified, getting latest 
build info from Jenkins")
+                job_info = self.jenkins_server.get_job_info(self.job_name)
+                build_number_to_check = job_info['lastBuild']['number']
+            else:
+                build_number_to_check = self.build_number
+
+            self.log.info(f"Getting build info for build number: 
#{build_number_to_check}")
+            build_info = self.jenkins_server.get_build_info(job_name, 
build_number_to_check)
+            building = build_info['building']
+            return building
+        except jenkins.NotFoundException as err:
+            raise AirflowException(f'Jenkins job status check failed. Final 
error was: {err.resp.status}')

Review comment:
       According to the source code of `get_job_info` & `get_build_info` there 
is no case of raising `NotFoundException`
   This is an internal exception of the functions but once caught the functions 
raise `JenkinsException`
   
   
https://opendev.org/jjb/python-jenkins/src/commit/d1e469649574883bc531d35fb3aee207f45c15a5/jenkins/__init__.py#L632
   
   
https://opendev.org/jjb/python-jenkins/src/commit/d1e469649574883bc531d35fb3aee207f45c15a5/jenkins/__init__.py#L452




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to