This script is to check for Duplicate Ticket with same Summary name that are open. Link the duplciate ticket and close.
def issueSummary = issue.fields.summary
logger.info('issue summary is : ' + issueSummary)
def jqlSearch = "summary ~ \"${issueSummary}\""
Map<String, Object> searchResult = get('/rest/api/2/search')
.queryString('jql', jqlSearch)
.asObject(Map)
.body
def issues = (List<Map<String, Object>>) searchResult.issues
def matchingIssues = []
issues.forEach
{
if(it.summary.contains(issueSummary) && it.fields.status.name != "Closed")
{
matchingIssues.add(it.key)
logger.info('issues with matching summary : ' + matchingIssues)
matchingIssues.forEach{
// Specify the source issue
final sourceIssueKey = "TEST-1"
// Specify the target issue
final targetIssueKey = "TEST-2"
// Specify the link type to use
final linkType = "Relates"
// Create the issue link between both issues
def link = post('/rest/api/2/issueLink')
.header('Content-Type', 'application/json')
.body([
type: [ name: linkType ],
outwardIssue: [ key: sourceIssueKey ], // This is the issue that the link 'starts' at.
inwardIssue: [ key: targetIssueKey ] // This is the issue that the link 'finishes' at.
])
.asString()
// Validate the link was created correctly
(link.status == 201) ? "Success - The issues with the key of ${sourceIssueKey} and ${targetIssueKey} have been linked with the '${linkType}' link type." : "${link.status}: ${link.body}"
}
}
}