Archive Projects with no Recent Updates

automateproject

Overview

Archive all projects in which no issues have been created or updated in the last 365 days. Use this script as a one-off action using the Script Console, or schedule it as a regular clean up a task using the Jobs feature.

Example

As an administrator, I want to ensure my Jira instance is efficient and uncluttered. One way to do this is to set up a monthly scheduled job that archives all projects that have been inactive for over a year.

Good to Know

  • The criteria used by this script, "Tickets not created or updated in the last 365 days" can be easily changed as it's in the JQL format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.project.archiving.ArchivedProjectService import org.apache.log4j.Level import org.apache.log4j.Logger def projectManager = ComponentAccessor.projectManager def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser def searchService = ComponentAccessor.getComponent(SearchService) def archivedProjectService = ComponentAccessor.getComponent(ArchivedProjectService) def log = Logger.getLogger(getClass()) log.setLevel(Level.DEBUG) def projectsToArchive = projectManager.projects.findAll { project -> // JQL criteria to search within projects. If it returns anything, the project DOESN'T get archived def jqlSearch = "project in (${project.key}) AND (updated > -365d OR created > -365d)" def parseResult = searchService.parseQuery(user, jqlSearch) if (!parseResult.valid) { log.warn("The JQL '${jqlSearch}' is not valid. Parse result: ${parseResult.errors}") return false } searchService.searchCount(user, parseResult.query) == 0 } projectsToArchive.each { project -> def validationResult = archivedProjectService.validateArchiveProject(user, project.key) if (validationResult.valid) { archivedProjectService.archiveProject(validationResult) log.debug("Project ${project.key} has been archived") } else { log.warn("Project ${project.key} could not be archived: ${validationResult.errorCollection}") } }