Uploaded image for project: 'Jira Service Management Data Center'
  1. Jira Service Management Data Center
  2. JSDSERVER-12512

Assets Automation fails to execute groovy script when run by a scheduled event

XMLWordPrintable

      Issue Summary

       The assets automation rule to run the groovy script executes fine manually but doesn't give expected results when run by a scheduled event.

      This is reproducible on Data Center: yes

      Steps to Reproduce

      1. Create a groovy script that runs a JQL and logs the issue details as in TestScript.groovy Create some Jira issues that match the JQL present in the script.
      2. Add this script to Assets Automation and run it manually. It runs fine and displays the issue details in the logs.
      3. Now, add the script to the scheduler and verify the log results.

      Expected Results

      The script runs fine when called by a scheduled event and displays the issue details in the log.

      Actual Results

      The script fails and throws an exception in the log during a scheduled event:

      def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
      

       And displays the below error in the log.

      2023-03-21 17:53:00,442 [insight-event-3] | AutomationRuleGroovyScriptAction, Unexpected error: Incorrect usage of JIRA/lucene search API. You can only create/use: ManagedIndexSearcher inside a context (request or Jira-Thread-Local). Check: JiraThreadLocalUtils for details.
      java.lang.IllegalStateException: Incorrect usage of JIRA/lucene search API. You can only create/use: ManagedIndexSearcher inside a context (request or Jira-Thread-Local). Check: JiraThreadLocalUtils for details.
              at com.atlassian.jira.index.ManagedIndexSearcherFactory.createFrom(ManagedIndexSearcherFactory.java:15) ~[classes/:?]
              at com.atlassian.jira.issue.index.ThreadLocalSearcherCache$Cache.retrieveEntitySearcher(ThreadLocalSearcherCache.java:142) ~[classes/:?]
              at com.atlassian.jira.issue.index.ThreadLocalSearcherCache.getSearcher(ThreadLocalSearcherCache.java:40) ~[classes/:?]
              at com.atlassian.jira.issue.index.DefaultIndexManager.getEntitySearcher(DefaultIndexManager.java:1014) ~[classes/:?]
              at com.atlassian.jira.issue.index.DefaultIndexManager.getIssueSearcher(DefaultIndexManager.java:990) ~[classes/:?]
              at sun.reflect.GeneratedMethodAccessor1321.invoke(Unknown Source) ~[?:?]
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_311]
              at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_311]
              at com.atlassian.jira.config.component.SwitchingInvocationHandler.invoke(SwitchingInvocationHandler.java:38) ~[classes/:?]
              at com.sun.proxy.$Proxy59.getIssueSearcher(Unknown Source) ~[?:?]
      

      The actions from the script are not executed from a scheduled event inside a jira thread local context.

      Workaround

      Currently, there is no known workaround for this behavior. A workaround will be added here when available

        1. TestScript.groovy
          0.8 kB
          Sireesha

              Unassigned Unassigned
              1463fcb5e3fd Sireesha
              Votes:
              6 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: