jenkins中,slave节点有多种启动方式,其中一种是“Launch slave agents via Java Web Start”,即通过JNLP启动一个代理来启动slave。这种方式比较适用于slave部署在windows系统的计算机上。

jenkins中通过JNLP启动slave节点的配置问题_ip地址

官方描述如下:

Starts a slave by launching an agent program through       ​​JNLP​​. The launch in this case is initiated by the slave, thus slaves need not be IP reachable from the master (e.g. behind the firewall.) It is still possible to start a launch without GUI, for example as a Windows service.

这种启动方式的配置项中,有一个“Tunnel connection through”,可以用来配置JNLP使用指定的IP地址和端口,格式为:"HOST:PORT", ":PORT", or "HOST:"。

jenkins中通过JNLP启动slave节点的配置问题_ip地址_02

实际应用时,我指定了端口号,并且在master节点的计算机上加入了iptables的规则后,以这种方式启动slave时,却始终连接不上,怀疑jenkins服务端似乎并没有使用这个指定的端口,而是每次都随机分配端口。

在网上搜了搜,发现在master上还有一个配置的地方,在jenkins的“系统设置”里,需要设置JNLP端口的分配方式,可以随机或者指定端口,将其配置为和slave的一致就ok了。