adding windows slave node through groovy script

633 views
Skip to first unread message

Sumit Anurag

unread,
Jul 30, 2016, 6:08:09 PM7/30/16
to Jenkins Developers
hello,

I am using groovy script to add window slave node as below:
import hudson.model.Node.Mode
import hudson.slaves.*
import jenkins.model.Jenkins
def nodename = slave1.abc.com;
def nodelabel = slave1;
def os = windows;
def nodedesc = slavenode;
def getJNLPSecret(nodename){
for (slave in jenkins.model.Jenkins.instance.slaves) {
if (slave.name.equals(nodename)){
def secret = slave.getComputer().getJnlpMac();
println "Secret=" + secret
return;
}
}
println "Secret=Error"
return;
}
if(os.equals("windows")){
Jenkins.instance.addNode(
new DumbSlave(nodename,nodedesc,"C:\\Jenkins","1",
Node.Mode.EXCLUSIVE,nodelabel,new JNLPLauncher(),
new RetentionStrategy.Always(),new LinkedList()))
getJNLPSecret(nodename);
}else {
println "OS: " + os + " is not supported at this time";
}

but getting below error:
Building in workspace C:\jenkins\jobs\slaveinstallation\workspace
[workspace] $ C:\jenkins\tools\hudson.plugins.groovy.GroovyInstallation\grooovy_2.4.7\bin\groovy.bat C:\jenkins\jobs\slaveinstallation\workspace\hudson8618503514845447879.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\jenkins\jobs\slaveinstallation\workspace\hudson8618503514845447879.groovy: 3: unable to resolve class jenkins.model.Jenkins
 @ line 3, column 1.
   import jenkins.model.Jenkins
   ^

C:\jenkins\jobs\slaveinstallation\workspace\hudson8618503514845447879.groovy: 1: unable to resolve class hudson.model.Node.Mode
 @ line 1, column 1.
   import hudson.model.Node.Mode
   ^

C:\jenkins\jobs\slaveinstallation\workspace\hudson8618503514845447879.groovy: 21: unable to resolve class DumbSlave 
 @ line 21, column 1.
   new DumbSlave(nodename,nodedesc,"C:\\Jenkins","1",
   ^

C:\jenkins\jobs\slaveinstallation\workspace\hudson8618503514845447879.groovy: 22: unable to resolve class JNLPLauncher 
 @ line 22, column 31.
   Node.Mode.EXCLUSIVE,nodelabel,new JNLPLauncher(),
                                 ^

C:\jenkins\jobs\slaveinstallation\workspace\hudson8618503514845447879.groovy: 23: unable to resolve class RetentionStrategy.Always 
 @ line 23, column 1.
   new RetentionStrategy.Always(),new LinkedList()))
   ^

5 errors

Build step 'Execute Groovy script' marked build as failure
Finished: FAILURE


please guide me where I am missing.

Markus Winter

unread,
Jul 30, 2016, 7:14:55 PM7/30/16
to jenkin...@googlegroups.com

You have to use a system groovy script so you run in the JVM of the master. By running a plain groovy script you run in a separate JVM. No chance to add a slave this way.

Regards

Markus

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/3afc52f2-f010-473d-b04e-f1bf7b40e79c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages