詹金斯奴隶自我登记 [英] Jenkins Slave Self Register

查看:63
本文介绍了詹金斯奴隶自我登记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Jenkins主/从集群,但是我很难找到让新的从属自动向主注册的方法.

I am creating a Jenkins master/slave cluster and I am having trouble finding a way to have new slaves auto register themselves with the master.

我当前的设置是运行一些Terraform脚本,这些脚本将创建主服务器和5个从服务器.然后,我必须登录到主节点并管理Jenkins->管理节点->新节点,然后手动创建所需的节点数.

My current set up is I run some Terraform scripts that will create the master and 5 slaves. Then I have to log in to the master node and Manage Jenkins -> Manage Nodes -> New Node and manually create the number of nodes I want.

然后,我将RDP放入我的从站并运行命令java -jar agent.jar -jnlpUrl http://yourserver:port/computer/agent-name/slave-agent.jnlp.这可以很好地工作,但是我想要一种自动缩放代理数量的方法,而不必每次我创建一个新代理时都手动登录到从属服务器.

Then I RDP into my slaves and run the command java -jar agent.jar -jnlpUrl http://yourserver:port/computer/agent-name/slave-agent.jnlp. This works perfectly fine, but I would like a way to auto scale up/down the number of agents without having to manually log into the slaves every time I create a new one.

我是否缺少有关如何动态自注册节点的插件或一些文档?

Is there a plugin or some documentation I'm missing about how to dynamically self register nodes?

注意:这仅适用于Windows节点.我正在使用Kubernetes插件自动缩放Linux节点,但是K​​ubernetes没有稳定的Windows节点支持,所以我不能使用它.我必须支持经典的.NET应用程序(而不是.NET Core),所以我必须在Windows节点上进行构建.

NOTE: This only applies to windows nodes. I am using the Kubernetes plugin to auto scale up/down linux nodes, but Kubernetes does not have stable windows nodes support so I can't use that. I have to support classic .NET applications (not .NET Core) so I have to build on windows nodes.

推荐答案

这是我在Linux上使用的bash脚本,可以很容易地将其应用于Windows.

Here's a bash script I use on Linux, it could be adapted fairly easily for Windows.

#!/bin/bash

set -xe

MASTER_URL=$1
MASTER_USERNAME=$2
MASTER_PASSWORD=$3
NODE_NAME=$4
NUM_EXECUTORS=$5

# Download CLI jar from the master
curl ${MASTER_URL}/jnlpJars/jenkins-cli.jar -o ~/jenkins-cli.jar

# Create node according to parameters passed in
cat <<EOF | java -jar ~/jenkins-cli.jar -auth "${MASTER_USERNAME}:${MASTER_PASSWORD}" -s "${MASTER_URL}" create-node "${NODE_NAME}" |true
<slave>
  <name>${NODE_NAME}</name>
  <description></description>
  <remoteFS>/home/jenkins/agent</remoteFS>
  <numExecutors>${NUM_EXECUTORS}</numExecutors>
  <mode>NORMAL</mode>
  <retentionStrategy class="hudson.slaves.RetentionStrategy\$Always"/>
  <launcher class="hudson.slaves.JNLPLauncher">
    <workDirSettings>
      <disabled>false</disabled>
      <internalDir>remoting</internalDir>
      <failIfWorkDirIsMissing>false</failIfWorkDirIsMissing>
    </workDirSettings>
  </launcher>
  <label></label>
  <nodeProperties/>
  <userId>${USER}</userId>
</slave>
EOF
# Creating the node will fail if it already exists, so |true to suppress the
# error. This probably should check if the node exists first but it should be
# possible to see any startup errors if the node doesn't attach as expected.


# Run jnlp launcher
java -jar /usr/share/jenkins/slave.jar -jnlpUrl ${MASTER_URL}/computer/${NODE_NAME}/slave-agent.jnlp -jnlpCredentials "${MASTER_USERNAME}:${MASTER_PASSWORD}"

这有点类似于docker slave镜像中包含的代理启动器,但是在运行jnlp之前,它使用jenkins cli在jenkins上创建了节点.有些参数显然需要适应Windows.

This is somewhat similar to the agent launchers included in the docker slave images, but before it runs jnlp it uses the jenkins cli to create the node on jenkins. Some of the parameters would need adapting to windows obviously.

要获取该xml,最简单的方法是在Web ui中按所需方式创建一个节点,然后使用jenkins-cli进行检索.

and to get that xml the easiest way is to create a node how you want in the web ui then use jenkins-cli to retrieve it.

这篇关于詹金斯奴隶自我登记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆