jenkinsci/jenkins · error · IllegalStateException
Can't create job from CLI in
Error message
Can't create job from CLI in
What it means
`CreateJobCommand.run()`: when NAME has a '/' and the prefix resolves to an existing item that is NOT a `ModifiableTopLevelItemGroup` (i.e. not a Folder), IllegalStateException 'Can't create job from CLI in <group>' is thrown at the else branch. You can only create child jobs inside modifiable groups.
Source
Thrown at core/src/main/java/hudson/cli/CreateJobCommand.java:70
Jenkins h = Jenkins.get();
if (h.getItemByFullName(name) != null) {
throw new IllegalStateException("Job '" + name + "' already exists");
}
ModifiableTopLevelItemGroup ig = h;
int i = name.lastIndexOf('/');
if (i > 0) {
String group = name.substring(0, i);
Item item = h.getItemByFullName(group);
if (item == null) {
throw new IllegalArgumentException("Unknown ItemGroup " + group);
}
if (item instanceof ModifiableTopLevelItemGroup) {
ig = (ModifiableTopLevelItemGroup) item;
} else {
throw new IllegalStateException("Can't create job from CLI in " + group);
}
name = name.substring(i + 1);
}
Jenkins.checkGoodName(name);
ig.createProjectFromXML(name, stdin);
return 0;
}
}
View on GitHub (pinned to 2e228ff40b)
Solutions
- Target a Folder (ModifiableTopLevelItemGroup) as the parent.
- Install and use the Folders plugin to host nested jobs.
- Create at top level instead of nesting under a non-folder.
Example fix
// before: // # 'buildA' is a freestyle job, not a folder // java -jar jenkins-cli.jar create-job buildA/sub < config.xml // -> IllegalStateException: Can't create job from CLI in buildA // // after: parent must be a Folder // java -jar jenkins-cli.jar create-job myFolder < folder.xml // java -jar jenkins-cli.jar create-job myFolder/sub < config.xml
Defensive patterns
Strategy: type-guard
Type guard
// Parent must be a Folder/modifiable group to host child jobs
Item parent = h.getItemByFullName(group);
if (parent != null && !(parent instanceof ModifiableTopLevelItemGroup)) {
throw new IllegalStateException("Not a folder: " + group);
} Prevention
- Nest jobs only under Folders, never under non-folder items.
- Ensure the Folders plugin is installed for nested job creation.
When it happens
Trigger: Running `create-job somejob/child < config.xml` where 'somejob' exists but is a non-folder item (a regular job).
Common situations: Using a job as a folder parent; no Folders plugin so no real modifiable group; misunderstanding item hierarchy.
Related errors
- Can't create job from CLI in
- Unknown ItemGroup
- Unknown ItemGroup
- Job ' already exists
- Job ' already exists
AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14).
Data as JSON: /api/errors/fcca7c0a1666e641.
Report an issue: GitHub.