Matthew Clark Post Function Script - Add attachment from the Jira servers file system to the issue on creation (make sure to put as the last POST function)

Created by Matthew Clark
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))
    .copySourceFile(true)//you must do this otherwise it deletes the source file from the file system

Comments (0)