Scripting
OneDev uses Groovy scripts for dynamic behavior in several places — issue fields, job parameters, build spec inputs, and variable substitution. Define reusable scripts under Administration → Groovy Scripts; configuration elsewhere refers to them by name.

Scripts run on the OneDev server with access to server APIs such as OneDev.getInstance(...) and EditContext. The expected return type depends on where the script is used; the description shown for each scripting option in the UI summarizes it.
Issue Custom Fields
Issue custom fields can evaluate scripts for available choices and default values. Field visibility is configured separately via Show Conditionally; it does not use Groovy scripts.
The example below sets up module-based assignee defaults. Assume:
- Each module maps to a OneDev group with the same name (for example Front End and Back End).
- When creating an issue, the reporter selects a module, and the assignee defaults to that module's leader but can be changed to any module member.
1. Module field
Define a custom field named Module with type Enumeration. Set Available Choices to Evaluate script to get choices, and select a script with this content:
import io.onedev.server.OneDev
import io.onedev.server.service.GroupService
def choices = [:]
for (group in OneDev.getInstance(GroupService.class).query()) {
choices.put(group.name, null)
}
return choices
The script returns a map of choice labels to colors. Use null for the color when a choice does not need one.
2. Assignee choices
Define a custom field named Assignee with type User choice. Set Available Choices to Evaluate script to get choices, and select a script that limits assignees to members of the selected module:
import io.onedev.server.OneDev
import io.onedev.server.util.EditContext
import io.onedev.server.service.GroupService
def module = EditContext.get().getInputValue("Module")
def choices = []
if (module != null) {
def group = OneDev.getInstance(GroupService.class).find(module)
if (group != null) {
for (user in group.members) {
choices.add(user.name)
}
}
}
return choices
EditContext.get().getInputValue("Module") reads the current value of the Module field while the issue form is being edited.
3. Default assignee
Set the Assignee field Default Value to Evaluate script to get default value, and select a script that picks the module leader:
import io.onedev.server.util.EditContext
def moduleLeaders = ["Front End": "alice", "Back End": "bob"]
def module = EditContext.get()?.getInputValue("Module")
def leader = module != null ? moduleLeaders[module] : null
return leader != null ? [leader] : []
Return a list of user login names when Assignee allows multiple values. Return a single login name when it does not.
For a step-by-step walkthrough that also covers auto-assigning project owners, see Default Assignee.
Other Uses
| Location | Scripting options |
|---|---|
| Job parameters | Choices, default values, parameter matrix values/secrets |
| Build spec inputs | Choices and default values for typed inputs |
| Build spec and workspace variables | @script:<script name>@ and @script:builtin:<script name>@ |
Check the scripting option's description in the UI for the required return type. For job variables, see also Job Variables.