Blog - Isos Technology

A Groovy Way to Quickly Find All Projects Using a Workflow in Jira

Written by Amanda Kirk | Jan 25, 2022

Here at Isos, we often come across problems that could potentially take substantial effort and ask ourselves, "How can we provide a solution for clients that takes less time, less effort, less budget, and is easily repeatable?" One problem I came across recently was needing to find all projects using a specific workflow in an efficient and easily repeatable way.

Imagine you are asked by auditors or a manager about the members of a group. We all know that we can find this information in Jira by looking at the workflow under the Admin>Issues menu, but it is cumbersome to do so. You have to first drill into each workflow scheme that is associated with that workflow, and for each workflow scheme get the projects using that workflow scheme. Additionally, sometimes if too many projects are using a scheme, it won't even show the whole list in the UI! Imagine you have a workflow used in hundreds of projects across dozens of workflow schemes....this manual task is unnecessarily tedious.

In this blog post, I will show you how to quickly find all projects using a workflow by using a simple groovy script which can be re-used time and time again! To run this script, just pull up a groovy console in Jira. (Note that a groovy console comes with some typical add-ons like JMWE and may not be available out-of-the-box.) 

 

import com.atlassian.jira.component.ComponentAccessor
def projectManager = ComponentAccessor.projectManager
def workflowManager = ComponentAccessor.workflowManager
def workflowSchemeManager = ComponentAccessor.workflowSchemeManager
def sb = new StringBuffer()
 
//workflow to search for
def wfName = "BLOG: Simple Issue Tracking Workflow"
 
//a place to store results
def projects = []
//for each workflow scheme in Jira, find ones that contain our specified workflow workflowSchemeManager.assignableSchemes.each {
workflowSchemeManager.assignableSchemes.each{
    if (wfName in it.mappings.values()) {
    //add the project tied to this workflow scheme to our results
    projects += workflowSchemeManager.getProjectsUsing(it)
  }
}
 
 
//output results
projects*.key.each{
    //gets each project object by key
    def projectObj = projectManager.getProjectByCurrentKey(it.toString())
    //outputs name of project and key of project
    sb.append(projectObj.getName() + " : " + it.toString() + "\n")
}
 
return sb.toString()

 

As you can see from the above, we use the workflowSchemeManager from the Jira API to iterate over all workflow schemes in Jira. For each workflow scheme, we check if it uses our workflow and if it does, we take note of the project that is using it. You can also format the output anyway you'd like, so there is no need for exporting and formatting in an external tool. 

For a full list of user attributes you can get from the project using the above script, see the Project object in the API documentation here. Some common ones I use are:

  • project category
  • project lead
  • project key
  • project name

The only line needing editing is line 8, where you define the name of the workflow you are searching for.

And voila, it is as simple as that! I hope these script snippets can help speed your admin tasks or client needs. And as always, happy automating!