How to delete issue type using groovy

Manmohit Sehgal
Contributor
February 22, 2017

I want to delete issue types related to a project using groovy. I am able to find the issue types but I have not been able to find a method to delete the issue types. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.*
import com.atlassian.jira.issue.fields.config.*
import com.atlassian.jira.project.* 
import com.atlassian.jira.project.ProjectManager
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
log.setLevel(Level.DEBUG)
def issueTypeSchemeManager = ComponentAccessor.issueTypeSchemeManager
def projectManager = ComponentAccessor.projectManager
Project proj= projectManager.getProjectByCurrentKey("OP")
def issueTypes = issueTypeSchemeManager.getIssueTypesForProject(proj)
for(int i = 0; i < issueTypes.size(); i++){
	log.debug(issueTypes[i].name)
}

 

Thank you for the help.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Jonny Carter
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.
February 23, 2017

Walter's warning is a prudent one; make sure you're ready for the issue type to be deleted. Still, for those who are sure they're sure:

The polite way to do this is using the IssueTypeService, I believe:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.IssueTypeService

def issueTypeSchemeManager = ComponentAccessor.issueTypeSchemeManager
def issueTypeService = ComponentAccessor.getComponent(IssueTypeService)

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser


def projectManager = ComponentAccessor.projectManager
def proj= projectManager.getProjectByCurrentKey("OP")
def issueTypes = issueTypeSchemeManager.getIssueTypesForProject(proj)
issueTypes.each{ oldType ->
    def deleteRequest = new IssueTypeService.IssueTypeDeleteInput(oldType.id, null) //if you have a target issue type, use its id here instead of null
    def validationResult = issueTypeService.validateDeleteIssueType(currentUser, deleteRequest)
    issueTypeService.deleteIssueType(currentUser, validationResult)
}

Cowboys and others with a taste for adventure may prefer the IssueTypeManager.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.IssueTypeManager
def issueTypeManager = ComponentAccessor.getComponent(IssueTypeManager)

def issueTypeSchemeManager = ComponentAccessor.issueTypeSchemeManager
def projectManager = ComponentAccessor.projectManager
def proj= projectManager.getProjectByCurrentKey("OP")
def issueTypes = issueTypeSchemeManager.getIssueTypesForProject(proj)
issueTypes.each{ oldType ->
    issueTypeManager.removeIssueType(oldType.id, null) //replace null with target issue type if you have one
}
1 vote
Walter Buggenhout
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 22, 2017

I am not a groovy specialist, so I have no immediate answer to your question, but are you sure you want to do this? Issue types are associated with a JIRA project through an issue type scheme. They may also be associated with other projects using the same or other issue type schemes.

Deleting an issue type removes it from your JIRA instance, not just from your project. So you will only be able do do this if they are used nowhere else in your instance.

Maybe I'm slightly over-concerned, but I thought I'd mention it anyway smile!

Manmohit Sehgal
Contributor
February 22, 2017

Hi Walter,

Thank you for the concern but yes I am sure of doing this. I have another script which deletes the schemes, which I dont need for a specific JIRA instance. 

TAGS
AUG Leaders

Atlassian Community Events