def invoke(self, securitytoken=None, block=False, build_params=None, cause=None, files=None, delay=5): assert isinstance(block, bool) if build_params and (not self.has_params()): raise BadParams("This job does not support parameters") params = {} # Via Get string if securitytoken: params['token'] = securitytoken # Either copy the params dict or make a new one. build_params = build_params and dict(build_params.items()) or { } # Via POSTed JSON url = self.get_build_triggerurl(files, build_params) if cause: build_params['cause'] = cause # Build require params as form fields # and as Json. data = { 'json': self.mk_json_from_build_parameters(build_params, files) } data.update(build_params) response = self.jenkins.requester.post_and_confirm_status( url, data=data, params=params, files=files, valid=[200, 201, 303], allow_redirects=False) redirect_url = response.headers['location'] if not redirect_url.startswith("%s/queue/item" % self.jenkins.baseurl): if files: raise ValueError('Builds with file parameters are not ' 'supported by this jenkinsapi version. ' 'Please use previous version.') else: raise ValueError("Not a Queue URL: %s" % redirect_url) qi = QueueItem(redirect_url, self.jenkins) if block: qi.block_until_complete(delay=delay) return qi
def invoke(self, securitytoken=None, block=False, build_params=None, cause=None, files=None, delay=5): assert isinstance(block, bool) if build_params and (not self.has_params()): raise BadParams("This job does not support parameters") params = {} # Via Get string if securitytoken: params['token'] = securitytoken # Either copy the params dict or make a new one. build_params = dict(build_params.items()) \ if build_params else {} # Via POSTed JSON url = self.get_build_triggerurl() if cause: build_params['cause'] = cause # Build require params as form fields # and as Json. data = { 'json': self.mk_json_from_build_parameters(build_params, files) } data.update(build_params) response = self.jenkins.requester.post_and_confirm_status( url, data=data, params=params, files=files, valid=[200, 201, 303], allow_redirects=False) redirect_url = response.headers['location'] # # Enterprise Jenkins implementations such as CloudBees locate their # queue REST API base https://server.domain.com/jenkins/queue/api/ # above the team-specific REST API base # https://server.domain.com/jenkins/job/my_team/api/ # queue_baseurl_candidates = [self.jenkins.baseurl] scheme, netloc, path, _, query, frag = \ urlparse.urlparse(self.jenkins.baseurl) while path: path = '/'.join(path.rstrip('/').split('/')[:-1]) queue_baseurl_candidates.append( urlparse.urlunsplit([scheme, netloc, path, query, frag])) redirect_url_valid = False for queue_baseurl_candidate in queue_baseurl_candidates: redirect_url_valid = redirect_url.startswith( "%s/queue/item" % queue_baseurl_candidate) if redirect_url_valid: break if not redirect_url_valid: raise ValueError("Not a Queue URL: %s" % redirect_url) qi = QueueItem(redirect_url, self.jenkins) if block: qi.block_until_complete(delay=delay) return qi