JIRA - bulk delete attachments of specific project

Sehrish Gul December 8, 2022

I want to delete the all attachments of a specific project from JIRA. But i am unable to find any option for this. Kindly guide how can i delete the all attachments of a specific project for a defined date range.

1 answer

1 vote
Gokaraju gopi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 8, 2022

@Sehrish Gul 

Please run following script in scriptrunner

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.web.bean.PagerFilter;


def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.user
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)

def query = jqlQueryParser.parseQuery(jqlQuery)
def results = searchProvider.search(query, user, PagerFilter.unlimitedFilter)
results.issues.collect
{ issue -> issueManager.getIssueObject(issue.id) }
}

def user = ComponentAccessor.jiraAuthenticationContext.user
def jqlQuery = "project = \"First Project\" AND created>= -30d AND attachments is not EMPTY"
def issues = findIssues(jqlQuery)
issues.each{issue ->

def attachments = ComponentAccessor.attachmentManager.getAttachments(issue)
attachments.each {attachment ->
attachmentManager.deleteAttachment(attachment)
}

}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events