ScriptRunner

ScriptRunner is a Jira plugin for automating actions in response to events.

Concepts

  • Events are actions that take place in Jira.
  • Conditions are Jira expressions which must evaluate to boolean true in order for the script associated with the listener to run.
  • Scripts are expressed in p.r.comp.lang.groovy (Private)
  • Script listeners listen for events matching a specified condition and execute a script in response.

Script examples

Custom fields

def getCustomFields() {
  return get("/rest/api/2/field")
    .asObject(List)
    .body
    .findAll { (it as Map).custom } as List<Map>
}

def findCustomFieldIdByName(List<Map> customFields, String name) {
  def fieldId = customFields.find { it.name == name }?.id
  if (!fieldId) {
    logger.warn("Failed to find custom field named '${name}'")
    return
  }
  return fieldId
}

def customFields = getCustomFields()
def exampleFieldId = findCustomFieldIdByName(customFields, "Example field name")

Jira Cloud limitations

The original Jira Server plugin executes in the same JVM as the application itself, and as such it was possible to invoke any Jira API surface. This is not possible in the Jira Cloud edition, which instead uses webhooks.