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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

is there a way to bulk delete multiple components?

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

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.'

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.

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.

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 ! 

@Alexey Matveev _cPrime_,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

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.

@Alexey Matveev _cPrime_ thank you a lot for your advice! 

@Christos Moysiadis You are welcome!

0 votes

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!

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?

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

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')

 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you