Need to get automation rules using script runner jira

shiva December 9, 2024

 

Hi Team,

I am reaching out to inquire about the feasibility of retrieving automation rules using ScriptRunner for Jira. Our organization is currently utilizing ScriptRunner to automate various tasks within our Jira instance, and we are interested in exploring the possibility of programmatically accessing and managing our automation rules.

Could you please provide guidance on whether it is possible to use ScriptRunner to retrieve a list of automation rules, including their conditions, actions, and other relevant details? If so, could you offer insight into how to achieve this using ScriptRunner's API or scripting capabilities?

Specifically, we would like to know if it is possible to use ScriptRunner to:

  1. Retrieve a list of all automation rules in our Jira instance
  2. Get the details of a specific automation rule, including its conditions and actions
  3. Create, update, or delete automation rules using ScriptRunner scripts

To facilitate this inquiry, I have attempted to write a script using ScriptRunner to retrieve automation rules. Below is an example code snippet:

/////

 

import com.atlassian.jira.component.ComponentAccessor

import groovy.json.JsonOutput

def retrieveAutomationRules() {

try {

def automationService = ComponentAccessor.getComponentOfType(

Class.forName("com.atlassian.jira.workflow.WorkflowAutomationService")

)

if (!automationService) {

log.warn("Automation Service not found")

return null

}

// Debug: Print out the actual type of the service

log.warn("Automation Service Type: ${automationService.class}")

// Try to list methods of the service

def methods = automationService.class.methods.collect { it.name }

log.warn("Available Methods: ${methods}")

// Attempt to retrieve rules using available methods

def rulesMethod = automationService.class.methods.find {

it.name.toLowerCase().contains("getrules") ||

it.name.toLowerCase().contains("list")

}

if (rulesMethod) {

def rules = rulesMethod.invoke(automationService)

// Debug: Print out the type of rules retrieved

log.warn("Rules Type: ${rules?.class}")

// If rules is a collection, iterate and log details

if (rules instanceof Collection) {

rules.each { rule ->

log.warn("Rule Details: ${rule}")

log.warn("Rule Class: ${rule.class}")

}

}

return rules

}

log.warn("No rules retrieval method found")

return null

} catch (Exception e) {

log.error("Error retrieving automation rules: ${e.message}", e)

return null

}

}

return retrieveAutomationRules()

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
PRODUCT PLAN
STANDARD
AUG Leaders

Atlassian Community Events