Forums

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

Delete attachments based on a JQL Query

Brian Taylor
Contributor
February 26, 2023

I have a one-off use case where I have issues under a specific epic and want to remove attachments for all stories under that epic. 

I do have script runner but have not found an example to accomplish this task. 

Appreciate any help that can be provided. 

1 answer

1 accepted

0 votes
Answer accepted
George Kopsachilis
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 27, 2023

You might find this video useful - https://youtu.be/ebImmxh_2Yw 

Brian Taylor
Contributor
February 28, 2023

I also recently found this video but did not have automation installed yet.  We are in the process of testing 9.4 and the automation built into JIRA and this method did work. 


I also worked with Scriptrunner on an older script that does work as well. 

import com.atlassian.jira.bc.issue.search.SearchService // <-- add new import
import com.atlassian.jira.issue.MutableIssue; // <-- add new import
// more imports
import com.atlassian.jira.component.ComponentAccessor

def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser) // <-- changed here
def searchService = ComponentAccessor.getComponent(SearchService) // <-- changed to Search Service

def query = jqlQueryParser.parseQuery(jqlQuery)
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter()) // <-- changed here
search.results.collect { issue ->
issueManager.getIssueObject(issue.id)
}
}

def attachmentManager = ComponentAccessor.getAttachmentManager()
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def jqlQuery = "your-jql-query"
def issues = findIssues(jqlQuery)
issues.each{issue ->
def attachments = attachmentManager.getAttachments((MutableIssue) issue) // <-- typecast it to MutableIssue
attachments.each {attachment ->
attachmentManager.deleteAttachment(attachment)
}
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.10
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events