title: How to add jenkins node via Java program
body: <p>I must manage Jenkins node via a Java program. I found this example but when I launch it do nothing, no error e no result on Jenkins interface:</p>
  <pre><code>    @Test
  public void test() {
      //fail(&quot;Not yet implemented&quot;);
      //Main.main(new String[]{&quot;-version&quot;});
      //Main.main(new String[]{&quot;-s&quot;, &quot;http://localhost:8080&quot;, &quot;-auth&quot;, &quot;admin:password&quot;, &quot;list-plugins&quot;});
      //Main.main(new String[]{&quot;-ssh&quot;});
      StringBuilder str = new StringBuilder(&quot;&lt;slave&gt;&quot;);
      str.append(&quot;  &lt;name&gt;nodo-test&lt;/name&gt;&quot;);
      str.append(&quot;  &lt;description&gt;test&lt;/description&gt;&quot;);
      str.append(&quot;  &lt;remoteFS&gt;/home/build/jenkins-node&lt;/remoteFS&gt;&quot;);
      str.append(&quot;  &lt;numExecutors&gt;1&lt;/numExecutors&gt;&quot;);
      str.append(&quot;  &lt;mode&gt;NORMAL&lt;/mode&gt;&quot;);
      str.append(&quot;  &lt;retentionStrategy class=\&quot;hudson.slaves.RetentionStrategy$Always\&quot;/&gt;&quot;);
      str.append(&quot;  &lt;launcher class=\&quot;hudson.plugins.sshslaves.SSHLauncher\&quot; plugin=\&quot;ssh-slaves@1.5\&quot;&gt;&quot;);
      str.append(&quot;    &lt;host&gt;nodo-test&lt;/host&gt;&quot;);
      str.append(&quot;    &lt;port&gt;22&lt;/port&gt;&quot;);
      str.append(&quot;    &lt;credentialsId&gt;xxxxxx&lt;/credentialsId&gt;&quot;);
      str.append(&quot;  &lt;/launcher&gt;&quot;);
      str.append(&quot;  &lt;label&gt;build&lt;/label&gt;&quot;);
      str.append(&quot;  &lt;nodeProperties/&gt;&quot;);
      str.append(&quot;  &lt;userId&gt;Marco&lt;/userId&gt;&quot;);
      str.append(&quot;&lt;/slave&gt;&quot;);
      //Main.main(new String[]{&quot;-s&quot;, &quot;http://localhost:8080&quot;, &quot;-auth&quot;, &quot;admin:password&quot;, &quot;create-node&quot;, str.toString()});
      
      Process process;
      try {
          process = Runtime.getRuntime().exec(&quot;java -jar ./jenkins-cli.jar -s http://localhost:8080/jenkins create-node nodo-test&quot;);
          OutputStream stdin = process.getOutputStream();
          InputStream stdout = process.getInputStream();
          BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
          writer.write(str.toString());
          writer.flush(); 
          writer.close();
          System.out.println(&quot;End runtime&quot;);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      
      System.out.println(&quot;End&quot;);
  }
  </code></pre>
  <p>What is wrong ? Is there a method to do the same thing without use jenkins-cli ?
  Thanks for your support.</p>
  <p>UPDATE:
  the code, in effect, show error on &quot;flush&quot;: &quot;Pipe is being closed&quot;.
  FYI I'm trying to add a node to a Jenkins server running in a docker image &quot;localhost:8080&quot;.</p>