Esempio n. 1
0
    def poke(self, context: 'Context') -> bool:
        self.log.info("Poking jenkins job %s", self.job_name)
        hook = JenkinsHook(self.jenkins_connection_id)
        is_building = hook.get_build_building_state(self.job_name,
                                                    self.build_number)

        if is_building:
            self.log.info("Build still ongoing!")
            return False
        else:
            self.log.info("Build is finished.")
            return True
 def grab_artifact_from_jenkins(url):
     """
     Grab an artifact from the previous job
     The python-jenkins library doesn't expose a method for that
     But it's totally possible to build manually the request for that
     """
     hook = JenkinsHook("your_jenkins_connection")
     jenkins_server = hook.get_jenkins_server()
     # The JenkinsJobTriggerOperator store the job url in the xcom variable corresponding to the task
     # You can then use it to access things or to get the job number
     # This url looks like : http://jenkins_url/job/job_name/job_number/
     url += "artifact/myartifact.xml"  # Or any other artifact name
     request = Request(method='GET', url=url)
     response = jenkins_server.jenkins_open(request)
     return response  # We store the artifact content in a xcom variable for later use
Esempio n. 3
0
    def test_client_created_default_http(self, get_connection_mock):
        """tests `init` method to validate http client creation when all parameters are passed """
        default_connection_id = 'jenkins_default'

        connection_host = 'http://test.com'
        connection_port = 8080
        get_connection_mock.return_value = mock. \
            Mock(connection_id=default_connection_id,
                 login='******', password='******', extra='',
                 host=connection_host, port=connection_port)

        complete_url = f'http://{connection_host}:{connection_port}/'
        hook = JenkinsHook(default_connection_id)
        self.assertIsNotNone(hook.jenkins_server)
        self.assertEqual(hook.jenkins_server.server, complete_url)
 def get_hook(self) -> JenkinsHook:
     """
     Instantiate jenkins hook
     """
     return JenkinsHook(self.jenkins_connection_id)
Esempio n. 5
0
 def get_hook(self):
     return JenkinsHook(self.jenkins_connection_id)