Hello All!
I am trying to add an attachment (PDF file) to a ticket upon ticket creation. I have engaged the post function "custom script post-function" with the following code:
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/application-data/jira/"
String fileName = "ACP620.pdf"
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)
I am getting the "No such file exists" error. Can someone advise on the correct way to do this?
Can you please confirm that on your Jira server there is a file in this path and it is owned by the user running Jira:
/var/atlassian/application-data/jira/ACP620.pdf
I actually made a mistake and missed a folder and now got it working. Thanks!
Is there a way to use a sharepoint file in the "PathtoFile" parameter?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not familiar with SharePoint but maybe the file/folder API is a good starting place for doing that.
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest
As long as you know the file path in SharePoint and can generate a token this should be double.
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 am glad to hear you worked this out, in ScriptRunner 7.11.0 we introduced HAPI, which makes scripting a lot simpler.
In this case, after upgrading, your post function could be reduced to a single line of code:
issue.addAttachment('/tmp/file.txt')
For more information see:
Cheers :)
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.