Create Unix Slave with Jenkins Groovy script

I would like to know how to create a unix-slave with Jenkins Groovy script and run the slave. I have the following code and it works great. However, it does not create an ssh parameter in the slave and does not start the slave. I can see JNLPLauncher (), I think I need to change it like ssh launcher. I would appreciate any help, even if it points to documentation, which I can't seem to find. Additionally, this code is designed to start the slave during build and remove the slave after the build is complete. I need to do a dynamic subordinate assignment according to an option selected by the user. Therefore any other ideas on how to do this are appreciated.

import jenkins.model.*
import hudson.model.*
import hudson.slaves.*

Jenkins.instance.addNode(
  new DumbSlave(
    "test-script",
    "test slave description",
    "/export/home/pe-deploy/",
    "1",
    Node.Mode.NORMAL,
    "test-slave-label",
    new JNLPLauncher(),
    new RetentionStrategy.Always(),
    new LinkedList()))

      

+3


source to share


2 answers


RemoteLauncher is probably the one you want.



0


source


This is the answer I found on the Cloudbees support site that got me where I needed to be. The important line is import hudson.plugins.sshslaves.*

because SSHLauncher is part of the plugin.

Source: https://support.cloudbees.com/hc/en-us/articles/218154667-create-agent-node-from-groovy



import jenkins.model.*
import hudson.model.*
import hudson.slaves.*
import hudson.plugins.sshslaves.*
import java.util.ArrayList;
import hudson.slaves.EnvironmentVariablesNodeProperty.Entry;

  List<Entry> env = new ArrayList<Entry>();
  env.add(new Entry("key1","value1"))
  env.add(new Entry("key2","value2"))
  EnvironmentVariablesNodeProperty envPro = new EnvironmentVariablesNodeProperty(env);
  Slave slave = new DumbSlave(
                    "agent-node","Agent node description",
                    "/home/jenkins",
                    "1",
                    Node.Mode.NORMAL,
                    "agent-node-label",
                    new SSHLauncher("agenNode",22,"user","password","","","","",""),
                    new RetentionStrategy.Always(),
                    new LinkedList())
  slave.getNodeProperties().add(envPro)
  Jenkins.instance.addNode(slave)

      

+5


source







All Articles