[Urgent] - Auto Creation of Bugs in JIRA

I have a requirement to create auto creation of bugs in JIRA for failed Test Cases. I have searched some code related to groovy scripts and we found using API Call I am going to create the JIRA Bugs using groovy scripts.

I have used as a keyword. But while running the Scripts, execution got completed, but I am unable to find the bugs in JIRA. Could anyone suggest what is the issue I am not getting this in JIRA

@Keyword
def JIRADefectCreation(String username, String password) throws MalformedURLException {
def String authorizationValue = username + “:” + password
def authString = “username:password”.getBytes().encodeBase64().toString()
//authorizationValue = "Basic " + authorizationValue.bytes.encodeBase64().toString()

	def body_req = '''{

“fields” : {
“Project” : {“Key” : “EAI”},
“issuetype” : {“name” : “Bug” },
“Summary” : “test”,
“Description” : “test”}
}’’’

	def connection = new URL("https://jira.digital.aig.net/rest/api/2/issue/").openConnection() as HttpURLConnection
	connection.setRequestMethod("POST")
	connection.setRequestProperty("Authorization", "Basic ${authString}")
	connection.doOutput = true
	connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
	connection.getOutputStream().write(body_req.getBytes("UTF-8"))
	//connection.getOutputStream().write(body_req.getBytes("UTF-8"))
	connection.connect()
	def postRC = connection.getResponseCode();
	println(postRC);
	if(postRC.equals(200)){
		println (connection.getInputStream().getText());
		
	}

Did you managed to make it work?
If yes please put here the code that you used.
Thank you

@keyword
def JIRABugCreation() throws MalformedURLException {
def userNameAndPassword = GlobalVariable.JIRAUSERNAME + “:” + GlobalVariable.JIRAPASSWORD
userNameAndPassword = "Basic " + userNameAndPassword.getBytes().encodeBase64().toString()
def body_req = ‘’’{
“fields”: {
“project”:
{
“key”: “QKP”
},
“summary”: “Unable to create the home Page Template under Language node”,
“description”: “Unable to create the home Page Template under Language node”,
“assignee”:{“name”:“ns”},
“priority”: {
“name”: “Medium”
},
“issuetype”: {
“name”: “Bug”
}
}
}’’’

def connection = new URL("https://jira.digital.aig.net/rest/api/2/issue/").openConnection() as HttpURLConnection
connection.setRequestMethod("POST")
connection.setDoOutput(true)
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty("Authorization", userNameAndPassword)
connection.getOutputStream().write(body_req.getBytes("UTF-8"))
connection.connect()
def postRC = connection.getResponseCode();
println(postRC);
if(postRC.equals(201)){
	def ResponseText = connection.getInputStream().getText();
	println (ResponseText);
	ArrayList defectcreationarray = ResponseText.toString().split(",")
	ArrayList defectkey= defectcreationarray.get(1).toString().split("key")
	GlobalVariable.G_defectid = defectkey.get(1).toString().substring(3, 9)
	println "Defect Key Created is" + GlobalVariable.G_defectid
	def update_test_execution = WS.sendRequest(findTestObject('JIRA-ExecutionStatus/ZAPI-FAIL-STATUS', [('exid') : GlobalVariable.G_executionid, ('exStatus') : statusID, ('defectid') : GlobalVariable.G_defectid]))
}
}
1 Like