Jenkins plugin, how to execute system command on remote node?

Our company’s Jenkins has master and two slave nodes. I am writing plugin for it. One of the things for plugin to do is to checkout some files from svn. This action cannot be extracted from plugin.
To do this I execute console command “svn checkout” from java code of my plugin. The problem is that files from svn are checked out to master, rather than to slave nodes.
How can I make files be checked out to slave?

  • Jenkins pipeline code auto trigger with multiple repositories through GitHub Organization Folder Plugin
  • Problems launching the slave agent via Java Web Start on Jenkins
  • Jenkin's build failing on npm install
  • Sonar analysing Maven 3 and multi language project using JENKINS
  • How to pass output from an upstream project to downstream projects in Jenkins
  • Jenkins trigger on-demand slaves in dockers
  • Jenkins Sonar plugin suddenly stops working
  • PackageApplication stopped working with OS X 10.10 (Yosemite) today
  • Jenkins job notification fails with “No git consumers for URI …”
  • Changing the user's uid in a pre-build docker container (jenkins)
  • Return parameters/results from a job(triggered by pipeline) back to the same pipeline
  • Gradle installation having a proxy issue
  • 2 Solutions collect form web for “Jenkins plugin, how to execute system command on remote node?”

    First you have these objects, usually received as parameters for perform method:

    Launcher launcher;
    AbstractBuild<?, ?> build;
    BuildListener listener;

    Then you have created and added arguments to an argumentListBuilder, maybe something like:

    ArgumentListBuilder command = new ArgumentListBuilder();
    command.addTokenized("xcopy /?");

    Then, do something like:

    ProcStarter ps = ProcStarter();
    ps = ps.cmds(command).stdout(listener);
    ps = ps.pwd(build.getWorkspace()).envs(build.getEnvironment(listener));
    Proc proc = launcher.launch(ps);
    int retcode = proc.join();

    ProcStarter will run the command at the node specified by the launcher instance. But please at least glance over the javadocs of all above classes before using, above is not direct copy-paste from working code.

    Here is code based on Hyde’s answer, suitable for the Groovy script console (at /script)

    def static Run(nodeName, runCommand)
        def output = new;
        def listener = new hudson.util.StreamTaskListener(output);
        def node = hudson.model.Hudson.instance.getNode(nodeName);
        def launcher = node.createLauncher(listener);
        def command = new hudson.util.ArgumentListBuilder();
        def ps = launcher.launch();
        ps = ps.cmds(command).stdout(listener);
        // ps = ps.pwd(build.getWorkspace()).envs(build.getEnvironment(listener));
        def proc = launcher.launch(ps);
        int retcode = proc.join();
        return [retcode, output.toString()]
    // for (aSlave in hudson.model.Hudson.instance.slaves) {
    (recode, output) = Run("build-slave9", "xcopy /?");
    println output;

    (Caveats: untested for programs that read stdin. Note the ByteArrayOutputStream, so don’t run programs with very long output. Untested for non-ASCII output.)

    Git Baby is a git and github fan, let's start git clone.