Azure Devops -> Jira Service Management: Keep Synced Attachments internal and comment impersonation

Introduction

Hello all,

Picture this: You’ve successfully synced Azure DevOps and Jira Cloud, with a fully operational JSM project up and running.

Now, suppose you come across a scenario where you’d prefer all attachments sent over to be treated as internal within JSM.

The solution lies in adding these attachments to an internal comment in JSM. By doing so, you ensure that these attachments remain hidden from the end-user’s view while being accessible for internal purposes.

Let’s dive in the code.

For the outgoing sync in ADO, we will send over the attachments like this:

replica.attachments = workItem.attachments

For the incoming sync in JSM, we are going to add the attachments to an internal comment, included in this use-case is comment impersonation so if the user exists with the same email adres, the proxy user will change.

Incoming JSM Code

if (firstSync){

issue.projectKey = "JSM"

issue.typeName = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "[System] Service request"

}

issue.summary = replica.summary

issue.description = replica.description

issue.labels = replica.labels

replica.addedAttachments.each { a ->

def comment = commentHelper.addComment( "!${a.filename}!" , [])[ 0 ]

comment.internal = true

comment.restrictSync = true

issue.comments += comment

}

issue.attachments = attachmentHelper.mergeAttachments(issue, replica)

replica.addedComments.each { it.executor = nodeHelper.getUserByEmail(it.author?.email) }

replica.changedComments.each { it.executor = nodeHelper.getUserByEmail(it.updateAuthor?.email) }

issue.comments = commentHelper.mergeComments(issue, replica, {it.internal = true ; it})

Thank you.