mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
support hierarchical ItemGroup on CLI copy
This commit is contained in:
1 parent
74d721845e
commit
7eeb79ed43
1 file changed
+23
-5
@@ -27,6 +27,7 @@ import jenkins.model.Jenkins;
|
||||
import hudson.model.TopLevelItem;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Item;
|
||||
import jenkins.model.ModifiableTopLevelItemGroup;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
|
||||
|
||||
@@ -49,15 +50,32 @@ public class CopyJobCommand extends CLICommand {
|
||||
public String dst;
|
||||
|
||||
protected int run() throws Exception {
|
||||
Jenkins h = Jenkins.getInstance();
|
||||
h.checkPermission(Item.CREATE);
|
||||
Jenkins jenkins = Jenkins.getInstance();
|
||||
jenkins.checkPermission(Item.CREATE);
|
||||
|
||||
if (h.getItem(dst)!=null) {
|
||||
if (jenkins.getItemByFullName(dst)!=null) {
|
||||
stderr.println("Job '"+dst+"' already exists");
|
||||
return -1;
|
||||
}
|
||||
|
||||
h.copy(src,dst);
|
||||
|
||||
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 IllegalArgumentException("Can't create job from CLI in " + group);
|
||||
}
|
||||
dst = dst.substring(i + 1);
|
||||
}
|
||||
|
||||
ig.copy(src,dst);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user