Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,365
Community Members
 
Community Events
168
Community Groups

Get an PDF Attachment file from a Jira Issue using Groovy script in ScriptRunner

Get an PDF Attachment file from a Jira Issue using Groovy script in ScriptRunner.

I am trying to get the attachment of a Jira issue in Jira Service Management(Server) using Groovy Script under ScriptRunner plugin.

Please help me in finding the solution.

Here is the code I am using now:

1). Getting  java.lang.StackOverflowError with this code: 

List attachments = aM.getAttachments(issue)

def attachmentID;
File attachmentFile;

if (!attachments.isEmpty()) {
for (Attachment a in attachments) {
String fileName=a.getFilename()
log.warn(fileName)
attachmentID = a.getId()
log.warn(attachmentID)


String storePath=pM.getAttachmentPath()
def attachmentFilePath = new File(storePath).path
attachmentFile= new File(attachmentFilePath,fileName)
log.warn(attachmentFile)
log.warn(attachmentFile.text)
}
}

 

2). This gives NullPointer Exception as File object is coming as "null"

File file = ComponentAccessor.getComponent(FileSystemAttachmentDirectoryAccessor.class).getAttachmentDirectory(issue).listFiles().find({
File it->
it.getName().equals(attachmentID)
});

if(file.exists()){
log.warn("File exists!!!");
}else{
log.warn("NOOOOOOOOOOOOOO");
}

Not sure what I am missing.

NOTE : I am new to Jira and Groovy.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events