Hey,

Trying to create a script that restarts all slaves using Jenkins 
Administrative Script console.

Script 1:
import hudson.util.RemotingDiagnostics;

createShellScriptCommand = "echo \"/usr/sbin/shutdown -r now"
grantExecutionPrvilige = "chmod +x /home/nirdevadm/shutdown.sh"
executeShellScriptCommand = "echo \"vm-pass\" | sudo -S 
'/home/nirdevadm/shutdown.sh'"

for (slave in hudson.model.Hudson.instance.slaves) {
    println slave.name;
    println RemotingDiagnostics.executeGroovy(createShellScriptCommand, 
slave.getChannel());
    println RemotingDiagnostics.executeGroovy(grantExecutionPrvilige, 
slave.getChannel());
    println RemotingDiagnostics.executeGroovy(executeShellScriptCommand, 
slave.getChannel());
}

Script 1 fails with:

cript1.groovy: 1: unexpected char: 0xFFFF @ line 1, column 32.
   echo "/usr/sbin/shutdown -r now
                                  ^

1 error

at 
org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at 
org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at 
org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
groovy.lang.MissingPropertyException: No such property: chmod for class: 
Script1
at 
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at 
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)

groovy.lang.MissingPropertyException: No such property: sudo for class: 
Script1
at 
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at 
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)

Script 2:


import hudson.slaves.SlaveComputer
import jenkins.model.Jenkins

createShellScriptCommand = "echo \"/usr/sbin/shutdown -r now"
grantExecutionPrvilige = "chmod +x /home/nirdevadm/shutdown.sh"
executeShellScriptCommand = "echo \"vm-pass\" | sudo -S 
'/home/nirdevadm/shutdown.sh'"

Jenkins.instance.getComputers()
        .findAll { it instanceof SlaveComputer }
        .each { computer ->
Process p = createShellScriptCommand.execute()
Process z = grantExecutionPrvilige.execute()
Process x = executeShellScriptCommand.execute() 
}
return;

Script 2 seems to compile and does NOT fail but it does nothing as the 
slaves are not restarted.


It all boils down to these 3 unix commands that I want to execute trough 
groovy (they work well in isolation, executed directly on the slave):
echo "/usr/sbin/shutdown -r now" > /home/nirdevadm/shutdown.sh
chmod +x /home/nirdevadm/shutdown.sh
echo "vm-pass" | sudo -S '/home/nirdevadm/shutdown.sh'


Any suggestions what am I doing wrong? 

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/6fcf0d22-7bca-409a-ba4d-1cb06ca336ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to