def create_jira_issue(self, server_url, username, password, issue_summary, issue_description, project_key, issue_type='Bug'):
"""
connect to jira server and create an issue under a specific project
"""
status = True
output_dict = {}
wdesc = "Creates a JIRA issue"
pSubStep(wdesc)
issue_summary = issue_summary.replace('"', " ")
issue_description = issue_description.replace('"', "-")
fetchuri = server_url
postdata_url=fetchuri+'/rest/api/2/issue/'
postdata = """
{
"fields": {
"project":
{
"key": \""""+project_key+"""\"
},
"summary": \""""+issue_summary+"""\",
"description": \""""+issue_description+"""\",
"issuetype": {
"name": \""""+issue_type+"""\"
}
}
}
"""
credential_handler=urllib2.HTTPPasswordMgrWithDefaultRealm()
credential_handler.add_password(None, postdata_url, username, password)
auth = urllib2.HTTPBasicAuthHandler(credential_handler)
userpassword = username + ":" + password
password = base64.b64encode(userpassword)
#Create an Authentication handler
opener = urllib2.build_opener(auth)
urllib2.install_opener(opener)
opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
#Create a POST request
headers={"Authorization" : "Basic "+password,"Content-Type": "application/json"}
request=urllib2.Request(str(postdata_url),postdata,headers)
try:
handler = urllib2.urlopen(request)
extension = json.loads(handler.read())
issue_id = str(extension['key'])
pNote("JIRA Issue Created. Issue-Id: {0}".format(issue_id))
output_dict["issue_id"] = issue_id
except Exception as e:
status = False
pNote("Problem creating JIRA issue." , "error")
pNote("JIRA Error Code: ({0})".format(e) , "error")
Utils.data_Utils.update_datarepository(output_dict)
Utils.testcase_Utils.report_substep_status(status)
return status
评论列表
文章目录