{"record":{"id":"75bc185d4ac1e993","repo":"theonedev/onedev","slug":"error-evaluating-groovy-script","errorCode":null,"errorMessage":"Error evaluating groovy script: ","messagePattern":"Error evaluating groovy script: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/util/GroovyUtils.java","lineNumber":91,"sourceCode":"        \t\tif (contribution.getScript().getName().equals(builtInScriptName)) {\n        \t\t\tscript = contribution.getScript();\n        \t\t\tbreak;\n        \t\t}\n        \t}\n    \t} else {\n        \tfor (GroovyScript each: OneDev.getInstance(SettingService.class).getGroovyScripts()) {\n        \t\tif (each.getName().equals(scriptName)) {\n        \t\t\tscript = each;\n        \t\t\tbreak;\n        \t\t}\n        \t}\n    \t}\n    \tif (script != null) {\n    \t\tif (script.isAuthorized()) {\n    \t\t\ttry {\n    \t\t\t\treturn evalScript(StringUtils.join(script.getContent(), \"\\n\"), variables);\n    \t\t\t} catch (Exception e) {\n    \t\t\t\tthrow new RuntimeException(\"Error evaluating groovy script: \" + scriptName, e);\n    \t\t\t}\n    \t\t} else {\n    \t\t\tthrow new ExplicitException(\"Unauthorized groovy script: \" + scriptName);\n    \t\t}\n    \t} else {\n    \t\tthrow new ExplicitException(\"Groovy script not found: \" + scriptName);\n    \t}\n    }\n    \n    public static Object evalScript(String scriptContent, Map<String, Object> variables) {\n    \ttry {\n\t    \tClass<?> scriptClass = compile(scriptContent);\n\t\t\tScript script;\n\t\t\ttry {\n\t\t\t\tObject instance = scriptClass.getDeclaredConstructor().newInstance();\n\t\t\t\tif (!(instance instanceof Script))\n\t\t\t\t\treturn scriptClass;\n\t\t\t\telse ","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/util/GroovyUtils.java#L73-L109","documentation":"GroovyUtils.evalScriptByName looks up a named Groovy script, checks its isAuthorized() flag, and evaluates it. When the script's evaluation throws any Exception, it is wrapped in a RuntimeException \"Error evaluating groovy script: <scriptName>\" with the original exception as cause.","triggerScenarios":"Calling evalScriptByName(scriptName, variables) where the named script exists and is authorized, but its content fails to compile or run (syntax error, missing variable, thrown exception inside the script, classpath issues).","commonSituations":"Scripts referencing variables not supplied in the variables map, groovy syntax errors after edits, scripts calling classes/methods not on the server classpath, or runtime exceptions like NPEs inside script logic.","solutions":["Read the cause chain of the RuntimeException — the root cause identifies the actual compile or runtime failure in the script.","Open the named script in administration > scripts and check for syntax errors; test the script content independently.","Ensure all variables the script references are passed in the variables map.","Verify any classes imported by the script exist on the server classpath and use fully-qualified imports if needed."],"exampleFix":"// before: script uses undefined variable\ndef count = pullRequest.comments.size() // not provided -> fails\n// after: supply it when evaluating\nMap<String, Object> vars = new HashMap<>();\nvars.put(\"pullRequest\", pullRequest);\nGroovyUtils.evalScriptByName(\"my-script\", vars);","handlingStrategy":"try-catch","validationCode":"Script script = scriptService.find(scriptName); // verify existence and authorized flag first\nif (script != null && script.isAuthorized()) { /* safe to evaluate */ }","typeGuard":null,"tryCatchPattern":"try {\n    return GroovyUtils.evalScriptByName(scriptName, variables);\n} catch (RuntimeException e) {\n    Throwable cause = ExceptionUtils.getRootCause(e);\n    log.error(\"Groovy script '{}' failed: {}\", scriptName, cause.getMessage(), cause);\n}","preventionTips":["Keep script variables and the variables map in sync.","Test scripts in a Groovy console before saving.","Keep scripts small and avoid opaque classpath dependencies."],"tags":["groovy","scripting","runtime"],"backgroundTag":"script-evaluation-failed","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}