Hi Team,
Can someone please help me to add an attachment using scripted post function?
I used the suggestion in below link and it looks like the attachment is getting deleted after the script execution, how can I ensure the script does not delete the file from the location.
def attachmentManager = ComponentAccessor.getAttachmentManager()
def pathManager = ComponentAccessor.getAttachmentPathManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.getLoggedInUser()
def bean = new CreateAttachmentParamsBean.Builder()
.file(new File("/appl/jira_shared/test.txt"))
.filename("text.txt")
.contentType("plain/txt")
.author(user)
.issue(issue)
.build()
attachmentManager.createAttachment(bean)
Regards,
Prashant
Hi Prashant,
Can you try the following code and see if it works.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
def attachmentManager = ComponentAccessor.getAttachmentManager()
def pathManager = ComponentAccessor.getAttachmentPathManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.getLoggedInUser()
def bean = new CreateAttachmentParamsBean.Builder()
.file(new File("/appl/jira_shared/test.txt"))
.filename("text.txt")
.contentType("plain/txt")
.author(user)
.issue(issue)
.copySourceFile(true)
.build()
attachmentManager.createAttachment(bean)
You may refer to https://docs.atlassian.com/software/jira/docs/api/8.5.5/com/atlassian/jira/issue/attachment/CreateAttachmentParamsBean.html for more details on CreateAttachmentParamsBean.
I hope this helps.
Cheers,
Moga
Edited based on the reply. Thanks!
Hi Moga,
Thanks a lot for your inputs here.
It worked. :-)
Changes the copySourceFile with Boolean value instead of a string.
.copySourceFile(true)
Prashant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.