简体   繁体   English

Jenkins:使用命令或Groovy脚本动态配置从节点地址

[英]Jenkins: configure slave node address dynamically using command or groovy script

I have kinda ssh slave build jenkins setup. 我有一个ssh slave build jenkins setup。

Jenkins server connect to Mac slave thru ssh. Jenkins服务器通过ssh连接到Mac从属服务器。 build ios apps there. 在那建立ios应用程式。 two remote nodes are configured in Jenkins connected to the Mac. 在连接到Mac的Jenkins中配置了两个远程节点。 The Mac has dhcp. Mac有dhcp。

Every time my mac starts I want to run a script that tell the Jenkin server to configure the node's IP address pointing to the dhcp address that the mac receives. 每当我的Mac启动时,我都想运行一个脚本,告诉Jenkin服务器配置指向Mac接收到的dhcp地址的节点的IP地址。 Since its dhcp it changes always. 自从它的dhcp以来,它总是在变化。

Is possible to configure such? 可以配置这样吗? using shell script or perl ... 使用shell脚本或perl ...

e.g. http://jenkins-server:8080/computer/mac-slave-enterprise/configure

is the node config url. 是节点配置网址。 If its possible to setup by sending host=10.1.2.100 & Submit=Save or something like this? 如果可以通过发送host = 10.1.2.100&Submit = Save进行设置或类似的方法?

I found it is possible run Groovy script at 我发现可以在以下位置运行Groovy脚本

http://jenkins/script

or from mac command line or sh script, 或通过mac命令行或sh脚本,

$ curl -d "script=<your_script_here>" http://jenkins/script

I tried to get some info with this code but no luck, seems I have create SSLLauncher, but lost in how to grab a launcher things. 我试图通过此代码获取一些信息,但是没有运气,似乎我已经创建了SSLLauncher,但是在如何获取启动器方面迷失了方向。 There is no direct setHost or setLauncher thing. 没有直接的setHost或setLauncher东西。

following the tutorial at, 遵循以下教程,

https://wiki.jenkins-ci.org/display/JENKINS/Display+Information+About+Nodes

but cannot set the host address. 但无法设置主机地址。

println("node desc launcher = " + aSlave.getComputer().getLauncher()); 
  //println("node desc launcher = " + aSlave.getComputer().getLauncher().setHost("10.11.51.70")); 
  println("node launcher host = " + aSlave.getComputer().getLauncher().getHost()); 

  hudson.plugins.sshslaves.SSHLauncher ssl = aSlave.getComputer().getLauncher(); 
  int port = ssl.getPort(); 
  String userName, password, privateKey; 
  userName = ssl.getUsername(); 
  password = ssl.getPassword(); 
  privateKey = ssl.getPrivatekey(); 

  println("user: "+userName + ", pwd: "+password + ", key: "+privateKey); 
// all these values returns null. 

Another way would be to just delete the node and recreate it. 另一种方法是只删除节点并重新创建它。

Here is some groovy on how to delete it from here : 这是有关如何从此处删除它的一些技巧:

  for (aSlave in hudson.model.Hudson.instance.slaves) { 
    if (aSlave.name == "MySlaveToDelete") { 
      println('===================='); 
      println('Name: ' + aSlave.name); 
      println('Shutting down node!!!!'); 
      aSlave.getComputer().setTemporarilyOffline(true,null); 
      aSlave.getComputer().doDoDelete(); 
    } 

And here is how to create one ( source ): 这是创建一个( )的方法:

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

Jenkins.instance.addNode(new DumbSlave("test-script","test slave description","C:\\Jenkins","1",Node.Mode.NORMAL,"test-slave-label",new JNLPLauncher(),new RetentionStrategy.Always(),new LinkedList())) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM