jenkinsci/jenkins · error · IllegalStateException
Can't create job from CLI in
Error message
Can't create job from CLI in
What it means
`CopyJobCommand.run()`: when the destination contains '/' and the prefix resolves to an existing item, but that item is NOT a `ModifiableTopLevelItemGroup` (e.g. it's a regular job, not a folder), IllegalStateException 'Can't create job from CLI in <group>' is thrown. Children can only be created inside modifiable groups (folders).
Source
Thrown at core/src/main/java/hudson/cli/CopyJobCommand.java:74
Jenkins jenkins = Jenkins.get();
if (jenkins.getItemByFullName(dst) != null) {
throw new IllegalStateException("Job '" + dst + "' already exists");
}
ModifiableTopLevelItemGroup ig = jenkins;
int i = dst.lastIndexOf('/');
if (i > 0) {
String group = dst.substring(0, i);
Item item = jenkins.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);
}
dst = dst.substring(i + 1);
}
ig.copy(src, dst).save();
return 0;
}
}
View on GitHub (pinned to 2e228ff40b)
Solutions
- Target a real Folder (which implements ModifiableTopLevelItemGroup) as the parent, not a job.
- Install the Folders plugin and create the parent as a Folder if you need nested jobs.
- Copy to a top-level name instead of nesting under a non-folder item.
Example fix
// before: // # 'freestyleA' is a freestyle job, not a folder // java -jar jenkins-cli.jar copy-job template freestyleA/newjob // -> IllegalStateException: Can't create job from CLI in freestyleA // // after: parent must be a Folder // java -jar jenkins-cli.jar create-job myFolder < folder.xml // a real Folder // java -jar jenkins-cli.jar copy-job template myFolder/newjob
Defensive patterns
Strategy: type-guard
Type guard
// Only allow nesting under a modifiable group (Folder)
public static boolean isModifiableGroup(Item parent) {
return parent instanceof ModifiableTopLevelItemGroup;
} Prevention
- Only nest jobs under Folders (ModifiableTopLevelItemGroup), never under regular jobs.
- Install the Folders plugin if nested jobs are required.
When it happens
Trigger: Running `copy-job <src> somejob/child` where 'somejob' is an existing non-folder item (e.g. a FreestyleProject). The code reaches the else branch at line 73-74 because the item isn't a ModifiableTopLevelItemGroup.
Common situations: Using a job name as if it were a folder; missing the CloudBees Folders plugin so the intended parent isn't a real folder; misreading Jenkins' 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/2a0f103040cd8841.
Report an issue: GitHub.