mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 22:12:25 +00:00
Added a CLI command to copy a job.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18834 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
716f50991b
commit
a63bdef0a4
1 file changed
+43
@@ -0,0 +1,43 @@
|
||||
package hudson.cli;
|
||||
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.TopLevelItem;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Copies a job from CLI.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class CopyJobCommand extends CLICommand implements Serializable {
|
||||
@Override
|
||||
public String getShortDescription() {
|
||||
return "Copies a job";
|
||||
}
|
||||
|
||||
@Argument(metaVar="SRC",usage="Name of the job to copy")
|
||||
public String src;
|
||||
|
||||
@Argument(metaVar="DST",usage="Name of the new job to be created.",index=1)
|
||||
public String dst;
|
||||
|
||||
protected int run() throws Exception {
|
||||
Hudson h = Hudson.getInstance();
|
||||
TopLevelItem s = h.getItem(src);
|
||||
if (s==null) {
|
||||
stderr.println("No such job '"+src+"' perhaps you meant "+ AbstractProject.findNearest(src)+"?");
|
||||
return -1;
|
||||
}
|
||||
if (h.getItem(dst)!=null) {
|
||||
stderr.println("Job '"+dst+"' already exists");
|
||||
return -1;
|
||||
}
|
||||
|
||||
h.copy(s,dst);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user