I have set up a global automation to copy attachments between 2 types of issues on 2 different projects.
When an attachment is added to the issue in project A, I want the attachment to copy over to the linked issue on project B.
The issue I am having with the automation is that it is duplicating the attachments.
For example, let's say I add one attachments image1.png to the issue in project A. This attachment then gets copied to the linked issue in project B (correct).
Then I add another attachment image2.png to the issue in project B.
But instead of just image2.png copying over to the issue in project A, both image1.png AND image2.png copy over.
So I end up with duplicate attachments on the issue in project A: image1.png, image1.png, image2.png.
Can anyone help configuring what I am trying to achieve here? I only want to copy over the new attachment added, not all existing attachments.
Here is the automation:
Ended up getting this working with a custom script (thanks Scriptrunner!)
Full script here:
import com.atlassian.jira.component.ComponentAccessor
def attachmentManager = ComponentAccessor.attachmentManager
def user = Users.getByName('Automated-Jira-User')
def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, user).getAllIssues()
def redirectedIssue
// Get the redirected linked issue
linkedIssues.each {
if(it.getLabels().toString().contains('ukisr-redirected-ticket') || it.getIssueType().name == 'Software Project Redirect v2' || it.getIssueType().name == 'Software Project Redirect - 1 approval'){
redirectedIssue = it
}
}
if(!redirectedIssue){ return }
// Get current attachments for both issues
def attachments = issue.attachments
def redirectedAttachments = redirectedIssue.attachments
def redirectedAttachmentsFileNames = []
// Get all file names for attachments in linked issue to compare later
redirectedAttachments.each{ redirectedAttachment ->
redirectedAttachmentsFileNames += redirectedAttachment.filename
}
attachments.each { attachment ->
// If attachment doesn't already exist on linked ticket, add it
if(!redirectedAttachmentsFileNames.contains(attachment.filename)){
// log.warn('attachment not on linked issue')
attachmentManager.copyAttachment(attachment, user, redirectedIssue.key)
}
}
I went with a simpler solution to this problem.
There is a delete all attachments function. So I just delete all the attachments and copy them back again to get round this whenever an issue has its attachment field edited.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Watching this I have some suggestions on the cloud that I have checked on, not for the DC/Server.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.