Run a remote command on all Jenkins slaves via Masters's script console

后端 未结 4 1749
执念已碎
执念已碎 2021-01-02 04:29

I want to run same shell command (very simple shell commands like ls) on all the UNIX slaves which are connected to the master by using the master\'s script co

4条回答
  •  礼貌的吻别
    2021-01-02 04:42

    import hudson.util.RemotingDiagnostics;
    
    print_ip = 'println InetAddress.localHost.hostAddress';
    print_hostname = 'println InetAddress.localHost.canonicalHostName';
    
    // here it is - the shell command, uname as example 
    uname = 'def proc = "uname -a".execute(); proc.waitFor(); println proc.in.text';
    
    for (slave in hudson.model.Hudson.instance.slaves) {
        println slave.name;
        println RemotingDiagnostics.executeGroovy(print_ip, slave.getChannel());
        println RemotingDiagnostics.executeGroovy(print_hostname, slave.getChannel());
        println RemotingDiagnostics.executeGroovy(uname, slave.getChannel());
    }
    

提交回复
热议问题