Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,932
Community Members
 
Community Events
168
Community Groups

How to check workflows that uses particular add-on in validators

Hello Community,

Good day! Can someone help me on how can I retrieve workflows that uses a specific plugin/add-on in validators. I'm using this code via Scriptrunner Console but the problem is that it does not display validators, only postfunction is displayed.

 

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 = 'descriptor of add-on'

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

String result = "Workflow;Function;Type;Action;Source-Step<br>"

workflows.each{workflow ->
def 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}.*/){
def nodeInfo = getNodeInfo(it,searchText)
if (nodeInfo){
result += "$workflow_name;$nodeInfo<br>"
}
}
}
}
}
result

String getNodeInfo(Node n, String search) {
String nodetext = ''
def valid_action = false
def valid_function = false
def valid_step = false
if (n.name() == 'function') {
def m = n.value() =~ /[^\[{]*/ + search + /[^\]}]*/
if (m) {
nodetext += m[0].toString() + ";"
}
def p = n.parent()
while (p) {
switch (p.name()) {
case 'post-functions':
valid_function = true
nodetext += "post-function;"; break
case 'validators':
valid_function = true
nodetext += "validator;"; break
case 'conditions':
valid_function = true
nodetext += "condition;"; break
case 'action':
valid_action = true
nodetext += "${p.attribute('name')} (${p.attribute('id')});"; break
case 'step':
valid_step = true
nodetext += "${p.attribute('name')} (${p.attribute('id')})"; break
case 'global-actions':
valid_step = true
nodetext += "GLOBAL"; break
case 'initial-actions':
valid_step = true
nodetext += "INITIAL"; break
}
p = p.parent()
}
}
if (valid_action && valid_function && valid_step) {
return nodetext
} else {
return ""
}
}

 

Thank you!

1 answer

2 votes
Fazila Ashraf Community Leader Jun 06, 2019

Hi @Alvin 

I came across this wonderful free plugin from Botron - https://marketplace.atlassian.com/apps/1219634/power-admin?hosting=server&tab=overview 

 

Using this, we can analyze usage of a custom field or workflow validator, postfunction, condition given by plugins in the jira instance. see https://botronsoft.atlassian.net/wiki/spaces/PA/pages/883195908/Finding+App+Usage for the details. 

Hope this helps!

Hi @Fazila Ashraf ,

Good day! Thank you for your response, I can clearly say that your suggestion helped us a lot! Furthermore, I also need to know to focus especially on the workflow part, the script above returns the steps on the workflow that is using a particular add-on , but for some reasons, only post-function add-ons are only displayed. Can you help? I also need to display Validators.

Best  Regards,

Alvin

Fazila Ashraf Community Leader Jun 17, 2019

Hi @Alvin 

For me, the power admin plugin gives the workflows which uses the plugin element as validators also.

And as per the documentation inhttps://botronsoft.atlassian.net/wiki/spaces/PA/pages/883195908/Finding+App+Usage#FindingAppUsage-Usage validators are also reported.

Could you raise a support case with them if its not working for you like that?

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events