How to find all workflows which are using postfunctions of a plugin

We need to upgrade a JIRA, but one of the plugins is not compatible.
How can we find all the workflows which are using the workflow functions from this plugin ?

3 answers

1 accepted

2 votes
Henning Tietgens Community Champion Aug 26, 2013

You could use the Script Runner plugin to search for more detailed uses. I wrote a script to create a list which than can be used e.g. in Excel for further investigations.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowManager
import java.util.regex.Matcher

String searchText = 'com.googlecode.jsu.workflow.'

WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager()
Collection<JiraWorkflow> workflows = workflowManager.getWorkflows()

String result = "Workflow;Function;Type;Action;Step\r\n"

workflows.each{workflow ->
    workflowXml = workflow.descriptor.asXML()
    Matcher m = workflowXml =~ /${searchText}/
    if (m.find()) {
        String workflow_name = "${workflow.name}${if(!workflow.isActive()){"(inactive)"} else ''}${if(workflow.isDraftWorkflow()){"(draft)"} else ''}"
        def wf = new XmlParser().parseText(workflowXml)
        List<Node> wf_flat = wf.depthFirst()
        wf_flat.each{
            if (it.text() ==~ /.*${searchText}.*/){
                result += "$workflow_name;${getNodeInfo(it,searchText)}\r\n"
            }
        }
    }
}
result

String getNodeInfo(Node n, String search) {
    String nodetext = ''
    nodetext += "${n.text() - search}"
    def p = n.parent()
    while (p) {
        switch (p.name()) {
            case 'post-functions':
                nodetext += ";post-function"; break
            case 'validators':
                nodetext += ";validator"; break
            case 'conditions':
                nodetext += ";condition"; break
            case 'action':
                nodetext += ";${p.attribute('name')} (${p.attribute('id')})"; break
            case 'step':
                nodetext += ";${p.attribute('name')} (${p.attribute('id')})"; break
            case 'global-actions':
                nodetext += ";GLOBAL"; break
            case 'initial-actions':
                nodetext += ";INITIAL"; break

        }
        p = p.parent()
    }
    return nodetext
}

You have to adapt the searchText to match the plugin.

Henning

That's a cool approach, not requiring to access JIRA 'behind the scenes'
Certainly a candidate for a build-in script (IMO)

Henning - this a beautiful solution. Thanks for sharing!

@Henning Tietgens  – quick question. in the getNodeInfo method – why are you using the minus operator here:

 nodetext += "${n.text() - search}"

 

It looks like it's removing the search term from nodetext...?  Not sure why you are doing that. Any tips / insight much appreciated!

Henning Tietgens Community Champion Apr 21, 2016

You're right. It's only for shorter list entries.

We are currently using a query on the database, but I'm wondering if there is another approach.
The query is something like

select workflowname
from jira.jiraworkflows
where descriptor like '%iamhuy%'

You could export all workflows as xml-files and then search in these files for that plugin (e.g. com.googlecode.jsu). But I guess searching in in the database is faster.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

70 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you