Uploaded image for project: 'SR for Jira - Development'
  1. SR for Jira - Development
  2. SRJIRA-2116

Script Registry throws error when workflow function implements CannedScript

    XMLWordPrintableJSON

    Details

    • Sprint:
      Sprint 27 - Ends Feb 15, Sprint 28 - Ends Apr 19, Sprint 29 - Ends 10 May
    • Critical Points:
      1.5

      Description

      If you create a workflow function that implements the CannedScript class so that you can configure it, then add it to a workflow, the Script Registry throws an error when run.

      java.lang.ClassNotFoundException: com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.Sample not found by com.onresolve.jira.groovy.groovyrunner [164]
      	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
      	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
      	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
      	at java_lang_ClassLoader$loadClass$0.call(Unknown Source)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry.getScriptInfo(ScriptRegistry.groovy:140)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry$_getWorkflowsInfo_closure2$_closure10$_closure12.doCall(ScriptRegistry.groovy:249)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry$_getWorkflowsInfo_closure2$_closure10.doCall(ScriptRegistry.groovy:244)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry$_getWorkflowsInfo_closure2.doCall(ScriptRegistry.groovy:226)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry.getWorkflowsInfo(ScriptRegistry.groovy:224)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry.doScript(ScriptRegistry.groovy:66)
      

      Here's an example script. Put it in the script root under com/onresolve/scriptrunner/canned/jira/workflow/postfunctions/. Configure a workflow to use this script post-function (it will be in the list as "Sample").

      package com.onresolve.scriptrunner.canned.jira.workflow.postfunctions
      
      import com.atlassian.jira.component.ComponentAccessor
      import com.atlassian.jira.issue.MutableIssue
      import com.onresolve.scriptrunner.canned.CannedScript
      import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
      import com.onresolve.scriptrunner.canned.util.BuiltinScriptErrors
      import com.onresolve.scriptrunner.canned.util.SimpleBuiltinScriptErrors
      import com.opensymphony.util.TextUtils
      import org.apache.log4j.Logger
      
      class Sample implements CannedScript {
      
          Logger log = Logger.getLogger(Sample)
          public static final String FIELD_SOME_CONFIG = 'FIELD_SOME_CONFIG'
      
          String getName() {
              "Sample"
          }
      
          String getDescription() {
              "Log stuff"
          }
      
          List getCategories() {
              ["Function"]
          }
      
      
          List getParameters(Map params) {
              [
                      ConditionUtils.getConditionParameter(),
                      [
                              Name       : FIELD_SOME_CONFIG,
                              Label      : 'Text to log',
                              Description: 'This will be written to the debug log',
                              Type       : 'text'
                      ]
              ]
      
          }
      
          public BuiltinScriptErrors doValidate(Map params, boolean forPreview) {
              BuiltinScriptErrors errorCollection = new SimpleBuiltinScriptErrors()
              if (!params[FIELD_SOME_CONFIG]) {
                  errorCollection.addError(FIELD_SOME_CONFIG, "You must provide debug text.")
              }
              errorCollection
          }
      
          Map doScript(Map params) {
              MutableIssue issue = params['issue'] as MutableIssue
              String text = params[FIELD_SOME_CONFIG] as String
      
              Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
              if (!doIt) {
                  return [:]
              }
      
              log.debug(text)
      
              [:]
          }
      
          String getDescription(Map params, boolean forPreview) {
              String htmlResult = ''
              if (params[ConditionUtils.FIELD_CONDITION] as String != '') {
                  htmlResult += 'If condition: <pre>' + TextUtils.htmlEncode(params[ConditionUtils.FIELD_CONDITION] as String) + '</pre> is true:<br>'
              }
              htmlResult += getName() + " log the text ${params[FIELD_SOME_CONFIG]}"
              return htmlResult
          }
      
          public Boolean isFinalParamsPage(Map params) {
              true
          }
      }
      

      The post function fires just fine, but breaks the Script Registry.

        Attachments

          Activity

            People

            Assignee:
            scheesley Stephen Cheesley
            Reporter:
            jcarter Jonny Carter
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: