Hi all,
I'm trying to read the content of a text file attached to an Issue.
The code I was trying to use is the following.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.attachment.Attachment
def issueManager = ComponentAccessor.getIssueManager()
def aM= ComponentAccessor.getAttachmentManager()
def pM = ComponentAccessor.getAttachmentPathManager()
def issue = issueManager.getIssueObject("TEST-129")
List attachments = aM.getAttachments(issue)
if (!attachments.isEmpty()) {
for (Attachment a in attachments) {
String fileName=a.getFilename()
log.warn(fileName)
String storePath=pM.getAttachmentPath()
def attachmentFilePath = new File(storePath).path
def attachmentFile= new File(attachmentFilePath,fileName)
log.warn(attachmentFile)
log.warn(attachmentFile.text)
}
}
It's quite rough, I know, and it obviously doesn't work :-)
Here below the logs I get.
2019-11-12 18:38:06,530 WARN [runner.AbstractScriptRunner]: new_ReadStructure_log.txt 2019-11-12 18:38:06,530 WARN [runner.AbstractScriptRunner]: /var/atlassian/application-data/jira/data/attachments/new_ReadStructure_log.txt 2019-11-12 18:38:06,532 WARN [common.UserScriptEndpoint]: Script console script failed: java.io.FileNotFoundException: /var/atlassian/application-data/jira/data/attachments/new_ReadStructure_log.txt (No such file or directory) at ReadAttachment.run(ReadAttachment.groovy:21)
I guess I'm missing some steps.
Any hints?
Thanks, Andrea
I'm sorry I've posted this one double :-(
Will proceed on https://community.atlassian.com/t5/Jira-Software-questions/How-to-read-a-text-file-attached-to-an-issue-with-scriptrunner/qaq-p/1226865
Sorry, Andrea
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.