Example scripts
To homepage
Jira

Archive Unused Projects
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira
Language |
groovy
// Number of days since last update on any issue
int numberOfDaysWithoutIssueUpdateLimit = 10
// A list to store the keys of projects to be archived
def projectKeysToArchive = []
Projects.getAllProjects().each { project ->
// If the project contains no issues then add it to the list of projects to be archived
if (project.getInsight().totalIssueCount == 0) {
projectKeysToArchive.push(project.key)
}
// If the project has not updated any issues in the specified timeframe then add it to the list of projects to be archived
def lastIssueUpdateTime = project.getInsight().lastIssueUpdateTime
if (lastIssueUpdateTime) {
def lastIssueUpdateTimestamp = Date.from(lastIssueUpdateTime.toInstant())
def currentDate = new Date()
def millisecondsDifference = Math.abs(currentDate.time - lastIssueUpdateTimestamp.time)
def daysSinceLastIssueUpdate = millisecondsDifference / (1000 * 60 * 60 * 24) as double
def roundedDaysSinceLastIssueUpdate = Math.round(daysSinceLastIssueUpdate)
if (roundedDaysSinceLastIssueUpdate >= numberOfDaysWithoutIssueUpdateLimit) {
projectKeysToArchive.push(project.key)
}
}
}
// Loop over each project key in the list of projects to be archived
projectKeysToArchive.each { key ->
// Archive the project
// Note you must be on a Premium or Enterprise plan to be able to use this API
post("/rest/api/3/project/${key}/archive")
.header("Content-Type", "application/json")
.asObject(Map)
logger.info("Archived the project with the key of ${key}")
}
"Archiving completed. Check the logs tabs to see what projects were archived and for any errors."
Having an issue with this script?
Report it here