Skip to main content
Example scripts
arrow icon
To homepage
Jira
Cloud icon
Cloud

Archive issues returned by a JQL Search

Created 1 year ago, Updated 1 month(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
groovy
// Construct the JQL to return the issues to be archived
def jqlQuery = "updated >= '-30d' and project = 'RRR'"

// Loop over each issue
def archivedIssues = Issues.search(jqlQuery).take(500).collect { issue ->
    // Archive the current issue
    def archiveIssue = put("/rest/api/3/issue/archive")
            .header("Content-Type", "application/json")
            .body(
                    issueIdsOrKeys: [issue.key]
            )
            .asObject(Map)

    // Validate the issue was archived correctly
    assert archiveIssue.status >= 200 && archiveIssue.status < 300
    issue.key
}

logger.info("The following issues were archived succesfully: ${archivedIssues}")
Having an issue with this script?
Report it here