How to Sync Issue Labels in Jira On-premise

    This article describes how to synchronize issue labels.

    Labels field is one of the standard fields. You can synchronize it as any other issue field. Check the label issue field reference.

    Source Instance

    Outgoing sync

    send them to the destination instance:

    replica.labels = issue.labels

    Specify the labels which should be sent

    If you want to sync only some of the existing labels, you can specify that directly in the outgoing sync

    For example, send only labels starting with pub_ :

    replica.labels = issue.labels.findAll { it.label.startsWith("pub_") }
    ...

    Destination Instance

    Incoming sync

    Create received labels on the destination side. It helps to create the labels automatically and add them to the label field.

    //add all labels from the replica to the synced issue
    issue.labels = replica.labels

    You can use nodeHelper getLabel in case you want to assign a new label to your issue, depending on the remote issue details.

    For example:  if the remote issue has type 'new feature request', label the issue 'uservoice'

    if (replica.issueType.name == "New Feature") {
       issue.labels += nodeHelper.getLabel("uservoice")
    }


    Syncing Labels from GitHub to Jira

    GitHub allows to include spaces in the labels, while it's impossible to have ones in Jira.

    Please use the following code in the Incoming sync on Jira side to sync labels from GitHub to Jira.

    The code helps to transform labels with spaces (received form GitHub) to the Jira required format(without spaces).

    issue.labels = replica.labels.collect { it.label = it.label.replace(" ", "_"); it }


    Syncing Labels on AzureDeOps

    Azure DevOps tags are equal to labels in Jira or other platforms that have a label field. Note that Azure DevOps uses the semicolon (;) as the tag separator. Therefore you should avoid using this character as part of your label/tag. 

    If you sync Azue DevOps tags to Jira you need to make sure that the sync rule includes code to remove spaces from Azure DevOps tags 

    The example below shows how to sync labels with spaces.

    Add the script rules into the incoming sync on the destination side where labels don't support spaces. In this example, it's Jira side incoming sync.

    issue.labels = replica.labels.collect { it.label = it.label.replace(" ", "_"); it }

    Jira label my;label will be synchronized as two separate tags my and label on the Azure DevOps instance.

    Azure DevOps tag my label will synchronized to Jira as mylabel if you use the example rule above.