You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Generate Hyperlinks for Issues Attachments

Overview

Generate a list of hyperlinks for the attachments of an issue, allowing the attachment to be downloaded from the link.

Example

I want to ensure all my issues have up-to-date attachments and old attachments are removed. Using this script so attachments are generated as hyperlinks, I can easily monitor and clean up old attachments.

Requirements

  • Jira Jira (8.0 - 8.14)
  • ScriptRunner for Jira ScriptRunner for Jira (6.18.0)
    
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.config.properties.APKeys import groovy.xml.MarkupBuilder // the key of the issue final String issueKey = 'JRA-1' def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey) assert issue: "Could not find issue with key $issueKey" def attachments = ComponentAccessor.attachmentManager.getAttachments(issue) if (!attachments) { return "No attachments found for issue $issueKey" } def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL) def stringWriter = new StringWriter() def content = new MarkupBuilder(stringWriter) content.html { p { ul { attachments.each { attachment -> li { a href: "$baseUrl/secure/attachment/${attachment.id}/${URLEncoder.encode(attachment.filename, 'UTF-8')}", attachment.filename } } } } } stringWriter.toString()
Discovered an issue? Report it here

Suggested for you