Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a text file attached to an issue using Scritprunner?

ABoerio
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 12, 2019

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)

image.png

image.png

I guess I'm missing some steps.

Any hints?

Thanks, Andrea

 

1 answer

0 votes
ABoerio
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2019

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events