def _find_job_url(self, job_name): # First we ask search box for suggestions of the job name search_url = '{base}/search/suggest?query={job_name}'.format( base=self.jenkins.baseurl, job_name=q_plus(job_name)) search_result = self.jenkins.requester.get_url(search_url, headers={ 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, allow_redirects=False) if search_result.status_code != 200: raise NotFound('Job %s not found in Jenkins', job_name) # Job will be first in the list full_job_name = search_result.json()['suggestions'][0]['name'] # Second, we ask search to give us suggested job search_url = '{base}/search/?q={job_name}'.format( base=self.jenkins.baseurl, job_name=q_plus(full_job_name)) search_result = self.jenkins.requester.get_url(search_url, allow_redirects=False) if search_result.status_code != 302: raise NotFound('Job %s not found in Jenkins', job_name) # Job location will be in search result's headers return search_result.headers['Location']
def get_build(self, buildnumber): assert isinstance(buildnumber, int) try: url = self.get_build_dict()[buildnumber] return Build(url, buildnumber, job=self) except KeyError: raise NotFound('Build #%s not found' % buildnumber)
def get_job_url(self, str_job_name): if str_job_name in self: return self.get_job_dict()[str_job_name] else: # noinspection PyUnboundLocalVariable views_jobs = ", ".join(self.get_job_dict().keys()) raise NotFound("Job %s is not known, available jobs" " in view are: %s" % (str_job_name, views_jobs))
def _find_job_url(self, job_name): search_result = self.jenkins.requester.get_url( self.jenkins.baseurl + '/search/suggest?query=' + job_name, headers={ 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest' }, allow_redirects=False) if search_result.status_code != 200: raise NotFound('Job %s not found in Jenkins', job_name) full_job_name = search_result.json()['suggestions'][0]['name'] search_result = self.jenkins.requester.get_url( self.jenkins.baseurl + '/search/?q=' + full_job_name, allow_redirects=False) if search_result.status_code != 302: raise NotFound('Job %s not found in Jenkins', job_name) return search_result.headers['Location']
def get_build_metadata(self, buildnumber): """ Get the build metadata for a given build number. For large builds with tons of tests, this method is faster than get_build by returning less data. """ assert isinstance(buildnumber, int) try: url = self.get_build_dict()[buildnumber] return Build(url, buildnumber, job=self, depth=0) except KeyError: raise NotFound('Build #%s not found' % buildnumber)
def delete_build(self, build_number): """ Remove build :param int build_number: Build number :raises NotFound: When build is not found """ try: url = self.get_build_dict()[build_number] url = "%s/doDelete" % url self.jenkins.requester.post_and_confirm_status(url, data='') self.jenkins.poll() except KeyError: raise NotFound('Build #%s not found' % build_number)
def get_buildnumber_for_revision(self, revision, refresh=False): """ :param revision: subversion revision to look for, int :param refresh: boolean, whether or not to refresh the revision -> buildnumber map :return: list of buildnumbers, [int] """ if self.get_scm_type() == 'svn' and not isinstance(revision, int): revision = int(revision) if self._revmap is None or refresh: self._revmap = self.get_revision_dict() try: return self._revmap[revision] except KeyError: raise NotFound("Couldn't find a build with that revision")