def test_get_build_data_with_default_build(self):
     expected_data = make_build_data()
     json_io = StringIO(json.dumps(expected_data))
     with patch('urllib2.urlopen', return_value=json_io) as mock:
         get_build_data('http://foo:8080',
                        Credentials('jrandom', '1password'), 'bar')
     self.assertEqual(mock.call_count, 1)
     self.assertRequest(
         mock.mock_calls[0][1][0],
         'http://foo:8080/job/bar/lastSuccessfulBuild/api/json',
         {'Authorization': 'Basic anJhbmRvbToxcGFzc3dvcmQ='})
Beispiel #2
0
 def test_get_build_data_with_default_build(self):
     expected_data = make_build_data()
     json_io = StringIO(json.dumps(expected_data))
     with patch('urllib2.urlopen', return_value=json_io) as mock:
         get_build_data(
             'http://foo:8080', Credentials('jrandom', '1password'), 'bar')
     self.assertEqual(mock.call_count, 1)
     self.assertRequest(
         mock.mock_calls[0][1][0],
         'http://foo:8080/job/bar/lastSuccessfulBuild/api/json',
         {'Authorization': 'Basic anJhbmRvbToxcGFzc3dvcmQ='})
 def get_build_info(self, build_number=None):
     """
     Gets build info from the Jenkins server
     :rtype: dict
     """
     build_number = build_number or self.get_build_number()
     self.build_info = get_build_data(self.jenkins_url, self.credentials,
                                      self.job_name, build_number)
     return self.build_info
Beispiel #4
0
 def get_build_info(self, build_number=None):
     """
     Gets build info from the Jenkins server
     :rtype: dict
     """
     build_number = build_number or self.get_build_number()
     self.build_info = get_build_data(
         self.jenkins_url, self.credentials, self.job_name, build_number)
     return self.build_info
 def test_get_build_data(self):
     expected_data = make_build_data(1234)
     json_io = StringIO(json.dumps(expected_data))
     with patch('urllib2.urlopen', return_value=json_io) as mock:
         build_data = get_build_data('http://foo:8080',
                                     Credentials('jrandom', '1password'),
                                     'bar', '1234')
     self.assertEqual(1, mock.call_count)
     request = mock.mock_calls[0][1][0]
     self.assertRequest(request, 'http://foo:8080/job/bar/1234/api/json',
                        {'Authorization': 'Basic anJhbmRvbToxcGFzc3dvcmQ='})
     self.assertEqual(expected_data, build_data)
 def factory(cls, credentials, job_name, build_number=None, url=None):
     """
     :param credentials: Jenkins credentials
     :param job_name: Jenkins job name
     :param build_number: Jenkins build number
     :param url: Jenkins url
     :return:
     """
     url = url or JENKINS_URL
     build_info = (get_build_data(url, credentials, job_name, build_number)
                   if build_number else None)
     return cls(credentials, job_name, url, build_info)
Beispiel #7
0
 def factory(cls, credentials, job_name, build_number=None, url=None):
     """
     :param credentials: Jenkins credentials
     :param job_name: Jenkins job name
     :param build_number: Jenkins build number
     :param url: Jenkins url
     :return:
     """
     url = url or JENKINS_URL
     build_info = (get_build_data(url, credentials, job_name, build_number)
                   if build_number else None)
     return cls(credentials, job_name, url, build_info)
Beispiel #8
0
 def test_get_build_data(self):
     expected_data = make_build_data(1234)
     json_io = StringIO(json.dumps(expected_data))
     with patch('urllib2.urlopen', return_value=json_io) as mock:
         build_data = get_build_data(
             'http://foo:8080', Credentials('jrandom', '1password'), 'bar',
             '1234')
     self.assertEqual(1, mock.call_count)
     request = mock.mock_calls[0][1][0]
     self.assertRequest(
         request, 'http://foo:8080/job/bar/1234/api/json',
         {'Authorization': 'Basic anJhbmRvbToxcGFzc3dvcmQ='})
     self.assertEqual(expected_data, build_data)
Beispiel #9
0
def find_publish_revision_number(credentials, br_number, limit=20):
    """Return the publish-revsion number paired with build-revision number."""
    found_number = None
    job_number = 'lastSuccessfulBuild'
    for i in range(limit):
        build_data = get_build_data(
            JENKINS_URL, credentials, PUBLISH_REVISION, build=job_number)
        if not build_data:
            return None
        # Ensure we have the real job number (an int), not an alias.
        job_number = build_data['number']
        if get_revision_build(build_data) == str(br_number):
            found_number = job_number
            break
        job_number = job_number - 1
    return found_number