Hello Everyone,
I need help getting my script to add an attachment to a ticket on transition. I've look at the other posts and have tried to use them without fail. Currently this is what I have, and am hoping someone will be able to help me get what is wrong.
//Custom Post-scrip function
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.attachment.TemporaryWebAttachment
import com.atlassian.jira.issue.attachment.TemporaryWebAttachmentManager
import webwork.action.ActionContext
def attachmentManager = ComponentAccessor.getAttachmentManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.loggedInUser
def bean = new CreateAttachmentParamsBean.Builder()
.file(new File("//server/folder/file.pdf"))
\\Path to folder
.filename("file.pdf")
\\File to attach
.contentType("Adobe Portable Document Format/PDF")
.author(user)
.issue(issue)
.copySourceFile(true) .build()
attachmentManager.createAttachment(bean)
You can try this script:
Try to put your attachment file on server where Jira is running from.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean def attachmentManager = ComponentAccessor.getAttachmentManager() def user = ComponentAccessor.getJiraAuthenticationContext()?.loggedInUser String pathToFile = "/var/atlassian/jira/" String fileName = "test.txt" String pathAndFile = pathToFile+fileName def bean = new CreateAttachmentParamsBean.Builder() .file(new File(pathAndFile)) .filename(fileName) .contentType("text/txt") .author(user) .issue(issue) .copySourceFile(true)//you must do this otherwise it deletes the source file from the file system .build() attachmentManager.createAttachment(bean)
That's the one I tried to update. I'm not going to be the one updating the file, so I was hoping to find a way to have it point to one of our windows file shares.
I tried to use the one provided by @Mathis Hellensberg but I kept getting an unexpected token error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well the problem is then with your windows file share. You get token error because that win file share requires you to be logged in as well. So in this script you would need to somehow login in your win file share and then execute script that I posted to you. There is no other way...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Trevor Nagy
Out of pure curiosity, I tried this myself. I'm getting stuck at (Access denied) for the path I'm using, but maybe it can be of some help?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.attachment.TemporaryWebAttachment
import com.atlassian.jira.issue.attachment.TemporaryWebAttachmentManager
import webwork.action.ActionContext
def attachmentManager = ComponentAccessor.getAttachmentManager()
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = issueManager.getIssueObject("HRSD-79")
def bean = new CreateAttachmentParamsBean.Builder()
.file(new File("C:/Users/mhellensb/Downloads"))
.filename("favicon-32x32.png")
.contentType("image/png")
.author(user)
.issue(issue)
.build()
//.copySourceFile(true)
attachmentManager.createAttachment(bean)
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.