def _create_version(self, version, released=False): method = '_create_version' commons.print_msg(Jira.clazz, method, 'begin') new_version = Object() new_version.description = "Generated from pipeline" new_version.name = version if released: new_version.userReleaseDate = datetime.datetime.now().strftime( "%-d/%b/%Y") new_version.project = Jira.project_id new_version.released = released jira_url = "{}/rest/api/2/version".format(Jira.jira_url) headers = {'Content-type': 'application/json'} commons.print_msg(Jira.clazz, method, jira_url) commons.print_msg(Jira.clazz, method, new_version.to_JSON()) try: # TODO: Remove auth from below... resp = requests.post(jira_url, new_version.to_JSON(), headers=headers, auth=(os.getenv('JIRA_USER'), os.getenv('JIRA_PWD')), timeout=self.http_timeout) if resp.status_code != 201: commons.print_msg( Jira.clazz, method, "Unable to add version {version} \r\n " "Response: {response}".format(version=version, response=resp.text), 'WARN') else: commons.print_msg(Jira.clazz, method, resp.text) except requests.ConnectionError as e: commons.print_msg(Jira.clazz, method, 'Connection error. ' + str(e), 'WARN') except Exception as e: commons.print_msg( Jira.clazz, method, "Unable to add version {verions}".format(version=version), 'WARN') commons.print_msg(Jira.clazz, method, e, 'WARN') commons.print_msg(Jira.clazz, method, 'end')
def create_chg(self, story_details=None): servicenow_create_chg_url = ServiceNow.servicenow_url + '/api/now/table/change_request' cr = Object() cr.category = "Software" cr.description = self._format_release_notes(story_details) cr.short_description = "Deployment of {app}-{version} to {env}".format( app=BuildConfig.project_name, version=BuildConfig.version_number, env=os.getenv('NEXT_ENVIRONMENT')) cr.assignment_group = 'CAB Approval' cr.work_start = '2018-08-10 23:59:59' cr.work_end = '2018-08-11 23:59:59' cr.cmdb_ci = 'Cloud Foundry' cr.start_date = '2018-08-10 23:59:59' cr.end_date = '2018-08-11 23:59:59' cr.reason = 'Continuous Deployment' # headers = {'Content-type': 'application/json', 'Accept': 'application/json', # 'Authorization': "Bearer {}".format(os.getenv('SERVICENOW_TOKEN'))} headers = { 'Content-type': 'application/json', 'Accept': 'application/json' } print(servicenow_create_chg_url) resp = requests.post( servicenow_create_chg_url, cr.to_JSON(), headers=headers, auth=(os.getenv('SERVICENOW_USER'), os.getenv('SERVICENOW_PWD')), ) resp_obj = json.loads(resp.text) print(resp) print(resp.text) print(resp_obj["result"]["number"])