Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Delete Projects using Groovy from console

Srinivas Patruni July 24, 2013
import com.atlassian.jira.ComponentManagerimport com.atlassian.jira.component.ComponentAccessorimport org.apache.log4j.Categoryimport com.atlassian.jira.bc.project.ProjectService.DeleteProjectValidationResultimport com.atlassian.jira.bc.project.ProjectService.DeleteProjectResultimport com.atlassian.jira.bc.project.ProjectServicedef ComponentManager componentManager = ComponentManager.getInstance()
def Category log = Category.getInstance("com.onresolve.jira.groovy")
def projectManager = ComponentManager.getInstance().getProjectManager()
def projectService = ComponentManager.getComponentInstanceOfType(ProjectService.class)
def user = componentManager.jiraAuthenticationContext?.user

def projectsList = projectManager.getProjectsFromProjectCategory(projectManager.getProjectCategoryObjectByNameIgnoreCase("No Category"))
for(p in projectsList) {
	try {
                def projectKey = p.key;
                final ProjectService.DeleteProjectValidationResult result =
                        projectService.validateDeleteProject(user, projectKey);
                final ProjectService.DeleteProjectResult projectResult =
                        projectService.deleteProject(user, result);
                if (projectResult.isValid()) {
                        log.info(" project " + projectKey + " correcty deleted");
                } else {
                        log.error("projet " + projectKey + " wrongly deleted "  + projectResult.getErrorCollection().getErrors());
                }
                //break
        } catch (Exception e) {
                log.error("Exception with project "+ p.key + "\n"+ e);
                break
        }
}

I don't see any logs writing. Is thre some thing wrong here for deleting projects from Script console?

1 answer

0 votes
SuhailM
Contributor
January 1, 2014

First check all log statements are enabled in log4j properties file.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events