{"record":{"id":"2a0f103040cd8841","repo":"jenkinsci/jenkins","slug":"can-t-create-job-from-cli-in","errorCode":null,"errorMessage":"Can't create job from CLI in ","messagePattern":"Can't create job from CLI in ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/hudson/cli/CopyJobCommand.java","lineNumber":74,"sourceCode":"        Jenkins jenkins = Jenkins.get();\n\n        if (jenkins.getItemByFullName(dst) != null) {\n            throw new IllegalStateException(\"Job '\" + dst + \"' already exists\");\n        }\n\n        ModifiableTopLevelItemGroup ig = jenkins;\n        int i = dst.lastIndexOf('/');\n        if (i > 0) {\n            String group = dst.substring(0, i);\n            Item item = jenkins.getItemByFullName(group);\n            if (item == null) {\n                throw new IllegalArgumentException(\"Unknown ItemGroup \" + group);\n            }\n\n            if (item instanceof ModifiableTopLevelItemGroup) {\n                ig = (ModifiableTopLevelItemGroup) item;\n            } else {\n                throw new IllegalStateException(\"Can't create job from CLI in \" + group);\n            }\n            dst = dst.substring(i + 1);\n        }\n\n        ig.copy(src, dst).save();\n        return 0;\n    }\n}\n","sourceCodeStart":56,"sourceCodeEnd":83,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/cli/CopyJobCommand.java#L56-L83","documentation":"`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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before:\n//   # 'freestyleA' is a freestyle job, not a folder\n//   java -jar jenkins-cli.jar copy-job template freestyleA/newjob\n//   -> IllegalStateException: Can't create job from CLI in freestyleA\n//\n// after: parent must be a Folder\n//   java -jar jenkins-cli.jar create-job myFolder < folder.xml  // a real Folder\n//   java -jar jenkins-cli.jar copy-job template myFolder/newjob","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only allow nesting under a modifiable group (Folder)\npublic static boolean isModifiableGroup(Item parent) {\n    return parent instanceof ModifiableTopLevelItemGroup;\n}","tryCatchPattern":null,"preventionTips":["Only nest jobs under Folders (ModifiableTopLevelItemGroup), never under regular jobs.","Install the Folders plugin if nested jobs are required."],"tags":["jenkins","cli","job","folder","itemgroup"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}