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!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.