Snippets

Adaptavist Archive Issues in DC from JQL

Created by Bobby Bailey

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+import com.atlassian.jira.issue.label.Label
+
+// Define the date before which the issues should be archived (01/01/2018)
+def dateBefore = Date.parse("yyyy-MM-dd", "2024-10-30")
+
+// Define the JQL query to find issues that are Resolved and created before 01/01/2018
+def jqlQuery = "status = Resolved AND created < '${dateBefore.format('yyyy-MM-dd')}'"
+
+Issues.search(jqlQuery).each { issue ->
+    Set<Label> labels = issue.getLabels()
+
+    if(!("archived" in issue.labels*.label) && !issue.isArchived()){
+        // No label and issue not recognised in the system as being archived
+
+        // True Archive
+        log.error("Archiving ${issue.key}");
+        issue.archive()
+
+        //Transition to Archived
+        //issue.transition('Archived')
+    }
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.