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.
Community moderators have prevented the ability to post new answers.
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 }
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 !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.