Is there a way to inspect the "attachment" field within Jira? we are looking for a specific type of attachment file.
Hi @PJB
To inspect the Attachment field in Jira for a specific file type, you can use Jira Automation or a ScriptRunner (if available) to check the file types attached to an issue. Here's how you can approach it:
Jira Automation doesn’t natively support inspecting attachments for specific file types directly, but you can work around this by using smart values and regular expressions.
Example Automation Rule:
{{issue.attachment.filename.match(".*\.pdf")}}
""
.pdf
If you have ScriptRunner for Jira, you can write a Groovy script to inspect attachments and determine if a specific file type is present.
Example Script:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issue
def issueManager = ComponentAccessor.getIssueManager()def attachmentManager = ComponentAccessor.getAttachmentManager()
Issue issue = issueManager.getIssueObject("ISSUE-KEY") // Replace with your issue keydef attachments = attachmentManager.getAttachments(issue)
def pdfFiles = attachments.findAll { it.filename.endsWith(".pdf") }
if (pdfFiles) {return "PDF file(s) found: ${pdfFiles*.filename}"} else {return "No PDF files attached."}
You may also refer to this post for additional information: https://community.atlassian.com/t5/Jira-questions/Use-Case-Verify-Attachment-Type-When-Transitioning/qaq-p/1631128
Best regards
Sam
If you are in a company-managed project it is possible validate attachments during create/ transitions with Jira expression-based validators.
I am from Forgappify, and we developed Jira Expression Validator, which is part of the Workflow Building Blocks for Jira app. Here is an example how to restrict .bmp, .exe, .bat, jam.dev file extensions:
issue.attachments.every(item => !item.filename.match('(bmp|exe|bat|jam.dev)$'))
It is also possible to inspect a mimeType, size, author, and even a create date of the attachments. I am leaving a link to our expression library in case you are interested. If you can elaborate on what exactly you need, I can help you write the expression.
I hope it will help.
Cheers
Thank you for answering the question.
It looks like you're new here. Sign in or register to get started.