Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

is there a way to bulk delete multiple components?

HyunSung Jang October 18, 2018

Hi Team,

How can i delete bulk component in jira? 

I have 1000 + component and i want to delete most of it, 

so deleting one by one would be cumbersome.

Is there a easy way to delete multiple component?

oh, I don't want just clearing a component field in issue.

I do really want delete it from project. 

thanks.

5 answers

2 votes
Alex Gallien
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.
August 6, 2019

If anyone else hits this problem, here is a Python 2.7 script you can use, replacing <base-url> and <project> accordingly for your environment. It requires requests be installed, but should be pretty easy to use.

import requests
import json
import getpass

# Username and password terminal input
username = raw_input('Jira Username: ')
password = getpass.getpass()

# Initiate session with requests.
s = requests.Session()

# Make initial request to grab a list of all <project> components.
r = s.get(
url='https://<base-url>/rest/api/2/project/<project>/components',
auth=(username, password),
headers={'Content-Type': 'application/json'}
)

full_list = r.json()

id_list = []

# Pull all components, and add their IDs to a list (id_list).
for comp in full_list:
id_list.append(comp.get('id'))

# Confirm that you want to run the update.
conf_resp = raw_input('This will update ' + str(len(id_list)) + ' components. Proceed? (y/n): ')

# Using that list, delete the component.
if conf_resp == 'y':
for id in id_list:
id_fix = s.delete(
url='https:///<base-url>/rest/api/2/component/' + id
)
else:
print 'Component update aborted.'
1 vote
Jorge Suarez
Contributor
April 8, 2020

Hi All (past and, more importantly, FUTURE!),

    I too came across this dilemma when trying to mass archive components.  Apparently there is no way to do this via REST API.  But there is a way to do it via UI.  I didn't want to click archive on each button since we had 90+ components.  After thinking a bit, I found that I can command my browser to do it.  

    Turns out all the Archive links in the "..." menu are all assigned to a class.  So in CHROME use the querySelectorAll to grab them, then issue a click for each one!

acomp = document.querySelectorAll(".archivecomponent_link");    

for (var i=0; i<acomp.length; i++){

    console.log(acomp[i].id); acomp[i].click();}

 

The DELETE button is a little trickier as it pops up a dialog box, but I assume it can also be automated, maybe wait 1 second for load, then query for Submit button and issue a "click()" on it?

Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 9, 2020

I think that there is a way to delete components using the REST API. 

https://docs.atlassian.com/software/jira/docs/api/REST/7.13.8/#api/2/component-delete

Anatoĺ Puciejeŭ
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 15, 2021

underrated anwser

0 votes
andrew_rosca
Contributor
February 4, 2021 edited

I did it via bash

API_USER={your username}
API_KEY={your API key}
API_URL=https://{your domain}.atlassian.net/rest/api/2

while IFS= read -r id
do
curl -s -X "DELETE" -u $API_USER:$API_KEY $API_URL/component/$id
echo "Deleted component $id"
done < <(curl -s -u $API_USER:$API_KEY $API_URL/project/DOM/components \
| jq -r '.[] .id')

 

0 votes
Capi [resolution]
Atlassian Partner
August 30, 2019

Hi @HyunSung Jang ,

I'm aware I'm posting really late, but this may be helpful to others who are facing the same problem.

One great alternative to bulk delete components without any coding or back-end work is by using Profields' Bulk Operations. You can see the documentation here, it does exactly what you were looking for.

bulk component deletion.png

The selection of the projects to be deleted can be done with simple searches or advanced queries in Profields' Project Navigator. 

Hope this was helpful!

0 votes
Alexey Matveev
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.
October 19, 2018
HyunSung Jang October 19, 2018

thanks for your advice

If I delete component from database directly, is it will causing any problem?

I'm considering execute sql query like this..

 

"delete from jiradb.component where cname like 'test%'"

 

this query shows me, delete over 500 rows..

I'm not confident to execute it is safe or not.

Alexey Matveev
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.
October 19, 2018

It will make your data in the database inconsistent. You will delete just components, but all references to this components from issues will stay. I would advise not to do it via SQL quieries.

HyunSung Jang October 19, 2018

yes.. you are right..

many issues will loose its component referencing if I delete component via SQL.

I don't care about it for now, but will reconsidering it

thank you for your help ! 

Christos Moysiadis
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.
October 19, 2018

@Alexey Matveev,I would like to ask you a question relevant to@HyunSung Jang previous!!! I know that it is the worst thing to touch the database!

Considering that he has 1000+ components.. Could it be faster to check with an SQL query which components have no issues and then use the Jira Rest Api ??? 

So i am thinking about a script with a JQL and then a loop to delete these components. Is my though right?

Forgive me if my thought is wrong but i am new to the script world :D

 

Best regards

CM

Alexey Matveev
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.
October 19, 2018

To tell you the truth I have a rule never to do any inserts or updates in the Jira database. I always use Jira Api to change anything in Jira.

I think it is feasible the way you want to do it. But you never know what can go wrong because it is not the right way to do. Everything must be done through Jira Api. Anyway test your solution first in QA and make a backup.

Christos Moysiadis
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.
October 19, 2018

@Alexey Matveev thank you a lot for your advice! 

Alexey Matveev
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.
October 19, 2018

@Christos Moysiadis You are welcome!

Suggest an answer

Log in or Sign up to answer