How to Automatically Synchronize Linked Issues (Jira Cloud)

This script synchronizes linked issues in Jira Cloud using Exalate. It retrieves the issuelinks from an issue and automatically synchronizes each linked issue, whether there’s one or multiple.

Script Overview

  1. Retrieve Issue Links: The script fetches the issue links for a specific Jira issue:
def issueLinks = httpClient.get("/rest/api/3/issue/" + issueKey.id).fields.issuelinks
  1. Ensure Iterable Format: The script ensures that issuelinks is treated as a list, whether it contains one or more links:
def issueLinksList = issueLinks instanceof List ? issueLinks : (issueLinks ? [issueLinks] : [])
  1. Synchronize the Links: It loops through the links and synchronizes them using syncHelper.exalate():
issueLinksList.collect { it ->
    if (it.inwardIssue) {
        def issueLinkKey = new com.exalate.basic.domain.BasicIssueKey(it.inwardIssue.id, it.inwardIssue.key)
        syncHelper.exalate(issueLinkKey)
    }
}

Final Solution

  • Source Side (Outgoing Sync): On the source side, you need to send the issue links to the destination.
replica.issueLinks = issue.issueLinks
def issueLinks = httpClient.get("/rest/api/3/issue/" + issueKey.id).fields.issuelinks

def issueLinksList = issueLinks instanceof List ? issueLinks : (issueLinks ? [issueLinks] : [])

issueLinksList.collect { it ->
    if (it.inwardIssue) {
        def issueLinkKey = new com.exalate.basic.domain.BasicIssueKey(it.inwardIssue.id, it.inwardIssue.key)
        syncHelper.exalate(issueLinkKey)
    }
}
  • Destination Side (Incoming Sync): On the destination side, you need to receive the issue links from the source. This is done by setting the issue.issueLinks:
issue.issueLinks = replica.issueLinks
  • This script handles both single and multiple issue links, ensuring that all linked issues are synchronized automatically.