JIRA: Automatically Close Issues After a Period of Time

There could be an opportunity for you to automatically close issues after a certain period of time in JIRA. You could always use the Bulk Update mechanism to bulk transition these issues, or you could let a Groovy script execute that for you automatically (after a set period of time). Here’s a script on how you can achieve this on your JIRA instance.

Prerequisites

  • Information from JIRA
    • JIRA project(s)
    • Transition ID from Done to Closed
    • Username that is able to execute the transition to Close
  • ScriptRunner for JIRA

Script to Use

The script was from a Groovy ScriptRunner bug ticket raised a few years ago. Thanks, Marcel!

The script can be downloaded from my Bitbucket repo here: close-issues.groovy @ Bitbucket

Where to make changes

// Global variables to be updated before utilising the script
int daysSinceResolved = 5 ; // days to check for issue closure
int actionId = 701; // transition id from Done to Closed
String project = "TEST, JIRA"; // target project key. To include more than 1 project, include the project keys in quotes
String previousStatus = "Done"; // status to check before closing
String username = "admin"; // acting user who has the privilege to transition issues to Closed
String comment = "Automatically closing issue since it has been resolved for ${daysSinceResolved} days.";
  • daysSinceResolved: number of days to check for closing issues.
  • actionId: the transition ID from the Done status to Closed
  • project: the project key(s) to fetch the issues to close
  • previousStatus: the name of the status to check before closing
  • username: the username of the user who can execute the transition from Done to Closed
  • comment: the comment to add once the transition to Closed is complete

Steps to Implement the Script

  1. Upload the Groovy script to the $JIRA_HOME/scripts directory.
  2. Ensure that the Groovy script is in 755 permissions, and owned by the user who starts JIRA:
    sudo chown jira:jira close-issues.groovy && chmod 755 close-issues.groovy
    
  3. In JIRA, go to Administration > Advanced > Services.
  4. Add a new Service, with the following information:
    • Name: an appropriate name for the service
    • Class: com.onresolve.jira.groovy.GroovyService
    • Schedule: Days per Week (Saturday and Sunday) and set the time to execute the service
  5. Click Save.
  6. Edit the newly created service to include the path of the Groovy script.
  7. Click Update.

Technology Consultant at ServiceRocket. Great knowledge in Atlassian JIRA. Blogger. Programmer. Anime Vector Artist.