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

Channa patna March 2, 2021

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
AUG Leaders

Atlassian Community Events