theonedev/onedev · error · RuntimeException
Error evaluating groovy script:
Error message
Error evaluating groovy script:
What it means
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.
Source
Thrown at server-core/src/main/java/io/onedev/server/util/GroovyUtils.java:91
if (contribution.getScript().getName().equals(builtInScriptName)) {
script = contribution.getScript();
break;
}
}
} else {
for (GroovyScript each: OneDev.getInstance(SettingService.class).getGroovyScripts()) {
if (each.getName().equals(scriptName)) {
script = each;
break;
}
}
}
if (script != null) {
if (script.isAuthorized()) {
try {
return evalScript(StringUtils.join(script.getContent(), "\n"), variables);
} catch (Exception e) {
throw new RuntimeException("Error evaluating groovy script: " + scriptName, e);
}
} else {
throw new ExplicitException("Unauthorized groovy script: " + scriptName);
}
} else {
throw new ExplicitException("Groovy script not found: " + scriptName);
}
}
public static Object evalScript(String scriptContent, Map<String, Object> variables) {
try {
Class<?> scriptClass = compile(scriptContent);
Script script;
try {
Object instance = scriptClass.getDeclaredConstructor().newInstance();
if (!(instance instanceof Script))
return scriptClass;
else View on GitHub (pinned to d44925c47c)
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.
Example fix
// before: script uses undefined variable
def count = pullRequest.comments.size() // not provided -> fails
// after: supply it when evaluating
Map<String, Object> vars = new HashMap<>();
vars.put("pullRequest", pullRequest);
GroovyUtils.evalScriptByName("my-script", vars); Defensive patterns
Strategy: try-catch
Validate before calling
Script script = scriptService.find(scriptName); // verify existence and authorized flag first
if (script != null && script.isAuthorized()) { /* safe to evaluate */ } Try / catch
try {
return GroovyUtils.evalScriptByName(scriptName, variables);
} catch (RuntimeException e) {
Throwable cause = ExceptionUtils.getRootCause(e);
log.error("Groovy script '{}' failed: {}", scriptName, cause.getMessage(), cause);
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Error evaluating groovy script:
- Unauthorized groovy script:
- Groovy script not found:
- Project not found:
- Invalid access token
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/75bc185d4ac1e993.
Report an issue: GitHub.