The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
SuhailM
Contributor
January 1, 2014

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

TAGS
AUG Leaders

Atlassian Community Events