Script runner: issues after upgrade from Jira 4.4 to jira 6.3

Dear,

Until now, we had JIRA 4.4.3 with Groovy Runner 2.0.7. We upgrade our instance in JIRA 6.3.15 with Groovy Runner 3.0.16.

The problem is with our previous version, we implemented a new functionlity in the plugin Groovy Runner 2.0.7: A SimplePostfunction.groovy, delivered by Henning Tietgens.

This functionnality was used to add groovy script in workflow postfunctions via the JIRA interface. For more details, you can refer to this ticket: https://answers.atlassian.com/questions/266218

 

My issue: The post function is used a lot of time, but when I try to see the workflow configuration I encounter an "Internal error" page. We found errors in logs:

"java.lang.Exception: Class com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SimplePostfunction could not be found, or could not be compiled  at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.ensureScriptCompiled(ScriptRunnerImpl.groovy:592)  at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.validateAndRunCannedInternal(ScriptRunnerImpl.groovy:394)  at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runCanned(ScriptRunnerImpl.groovy:371)"

 

I cannot update the configuration of workflows because I can't access to the JRA interface, so I try to solve the issue by adapting the groovy class but without sucess.

 

Please help

 

PS: I have added the script in attachment

1 answer

1 accepted

2 votes
Henning Tietgens Community Champion Jul 10, 2015

Try this

package com.onresolve.scriptrunner.canned.jira.workflow.postfunctions

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 SimplePostfunction implements CannedScript {

    Logger log = Logger.getLogger(SimplePostfunction.class)
    public static
    final String FIELD_ADDITIONAL_SCRIPT = 'FIELD_ADDITIONAL_SCRIPT'

    String getName() {
        "Simple scripted postfunction"
    }

    String getDescription() {
        "Runs a simple embedded script"
    }

    List getCategories() {
        ["Function"]
    }


    List getParameters(Map params) {
        [
                ConditionUtils.getConditionParameter(),
                [
                        Name       : FIELD_ADDITIONAL_SCRIPT,
                        Label      : 'Script',
                        Description: "Enter any customisations to the issue, e.g. hard-coding specific field values.",
                        Type       : "textarea",
                        cssClass: "CodeMirror CodeMirrorSmall",
                        Examples   : [
                                "Set issue summary": "issue.summary = \\'Cloned issue\\'",
                                "Set custom field" : "def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == \\'MyCustomFieldType\\'}\\n" +
                                        "issue.setCustomFieldValue(cf, \\'my value\\')"
                        ]
                ]
        ]

    }

    public BuiltinScriptErrors doValidate(Map params, boolean forPreview) {
        BuiltinScriptErrors errorCollection = new SimpleBuiltinScriptErrors()
        if (!params[FIELD_ADDITIONAL_SCRIPT]) {
            errorCollection.addError(FIELD_ADDITIONAL_SCRIPT, "You must provide an additional script.")
        }
        errorCollection
    }

    Map doScript(Map params) {
        MutableIssue issue = params['issue'] as MutableIssue
        Map transientVars = params['transientVars'] as Map

        Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
        if (!doIt) {
            return [:]
        }

        ConditionUtils.doAdditional(params[FIELD_ADDITIONAL_SCRIPT] as String, issue, [transientVars: transientVars])

        [:]
    }

    String getDescription(Map params, boolean forPreview) {
        getName() + " : Condition: <pre>" + TextUtils.htmlEncode(params[ConditionUtils.FIELD_CONDITION] as String) + "</pre> Script: <pre>" + TextUtils.htmlEncode(params[FIELD_ADDITIONAL_SCRIPT] as String) + "</pre>"
    }

    public Boolean isFinalParamsPage(Map params) {
        true
    }

}

and adapt the path of the script file according to the package (com/onresolve/scriptrunner/canned/jira/workflow/postfunctions/)

 

Henning

Also check the location of the file, it should be under <jira-home>/scripts (in the correct package directory), and not under web-inf/classes, or anywhere else.

Thank you Jamie and Henning. You're the best. :) The fix of Henning works very well and solve my issue.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you