hi,
I want to copy attachment of one jira to other jira ticket. can i do this by code.
Community moderators have prevented the ability to post new answers.
You could copy attachments from one issue to another like this
attachmentManager = componentManager.getAttachmentManager() pathManager = componentManager.getAttachmentPathManager() attachmentManager.getAttachments(issue).each {attachment -> filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString()) atFile = new File(filePath) if (atFile.exists()) { try { if (atFile.canRead()) { attachmentManager.createAttachmentCopySourceFile(atFile, attachment.filename, attachment.mimetype, attachment.author, newIssue, [:], attachment.created) } } catch (SecurityException se) { log.warn("Could not read attachment file. Not copying. (${se.message})") } } else { log.warn("Attachment file does not exist where it should. Not copying.") } }
issue is the source, newIssue is the target issue. This is Groovy, similar to Java. Hope it helps.
Henning
thanks.
this answer helped to write my java code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
With your above code, Is there a way to copy the attachment from a relative location on the server where Jira is being hosted from? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know. It's a "normal" file operation which should work if attachments in general are working in JIRA.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alright, no worries. Thanks anyhow
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.
I think it should work for sub-tasks, too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I added your code in my groovy script but I'm getting error
No such property: PathUtils for class:........
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to import it first.
import com.atlassian.jira.util.PathUtils
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the new Atlassian AttachmentManager API you can use:
attachmentManager.copyAttachment(attachment, user, newIssue.getKey().toString())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you only have a handfull of issues in which you need to perform thins, I would suggest doing this manually. If you only want to use code, and/or have a large amount of attachments that need to be moved over, you might want to have a look at the JIRA CLI plugin. Example commands can be found here, i thin kit should be possible to make something with those. Within JIRA itself, it is not possible to perform through code, unless you want to hack around the database, but I would advice against doing that.
Cheers,
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.