在上篇文章中介绍了在Jenkins中使用API方式创建节点和查询的方式,在这篇文章继续通过具体的示例来说明更新和删除的方法。
xml方式查询节点信息
- 查询全部节点的信息
liumiaocn:node liumiao$ curl "${jenkins_host_url}/computer/api/xml" 2>/dev/null |xmllint --format -
<?xml version="1.0"?>
<computerSet _class="hudson.model.ComputerSet">
<busyExecutors>0</busyExecutors>
<computer _class="hudson.model.Hudson$MasterComputer">
<action/>
<assignedLabel>
<name>master</name>
</assignedLabel>
<description>the master Jenkins node</description>
<displayName>master</displayName>
<executor/>
<executor/>
<icon>computer.png</icon>
<iconClassName>icon-computer</iconClassName>
<idle>true</idle>
<jnlpAgent>false</jnlpAgent>
<launchSupported>true</launchSupported>
<loadStatistics _class="hudson.model.Label$1"/>
<manualLaunchAllowed>true</manualLaunchAllowed>
<monitorData/>
<numExecutors>2</numExecutors>
<offline>false</offline>
<offlineCauseReason/>
<temporarilyOffline>false</temporarilyOffline>
</computer>
<computer _class="hudson.slaves.SlaveComputer">
<action/>
<assignedLabel>
<name>agent001</name>
</assignedLabel>
<description>jenkins agent 001</description>
<displayName>agent001</displayName>
<executor/>
<icon>computer-x.png</icon>
<iconClassName>icon-computer-x</iconClassName>
<idle>true</idle>
<jnlpAgent>true</jnlpAgent>
<launchSupported>false</launchSupported>
<loadStatistics _class="hudson.model.Label$1"/>
<manualLaunchAllowed>true</manualLaunchAllowed>
<monitorData/>
<numExecutors>1</numExecutors>
<offline>true</offline>
<offlineCauseReason/>
<temporarilyOffline>false</temporarilyOffline>
</computer>
<displayName>Nodes</displayName>
<totalExecutors>2</totalExecutors>
</computerSet>
liumiaocn:node liumiao$
- 查询创建的具体节点的信息
liumiaocn:node liumiao$ curl "${jenkins_host_url}/computer/agent001/api/xml" 2>/dev/null |xmllint --format -
<?xml version="1.0"?>
<slaveComputer _class="hudson.slaves.SlaveComputer">
<action/>
<assignedLabel>
<name>agent001</name>
</assignedLabel>
<description>jenkins agent 001</description>
<displayName>agent001</displayName>
<executor/>
<icon>computer-x.png</icon>
<iconClassName>icon-computer-x</iconClassName>
<idle>true</idle>
<jnlpAgent>true</jnlpAgent>
<launchSupported>false</launchSupported>
<loadStatistics _class="hudson.model.Label$1"/>
<manualLaunchAllowed>true</manualLaunchAllowed>
<monitorData/>
<numExecutors>1</numExecutors>
<offline>true</offline>
<offlineCauseReason/>
<temporarilyOffline>false</temporarilyOffline>
</slaveComputer>
liumiaocn:node liumiao$
修改节点信息
对节点信息进行如下内容的修改
修改内容 | 说明 | 修改值 |
---|---|---|
description | 节点描述 | jenkins agent 001 modified |
of executor | 并行可执行的Job数量 | 2 |
Remote root directory | Agent的远程数据目录 | /tmp/agent001 |
其实修改非常简单,只需要将xml的设定文件POST上去即可。
- 修改信息所用的xml
liumiaocn:jenkins liumiao$ cat demo/node/xml/agent001.xml
<?xml version='1.1' encoding='UTF-8'?>
<slave>
<name>agent001</name>
<description>jenkins agent 001 modified</description>
<remoteFS>/tmp/agent001</remoteFS>
<numExecutors>2</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/>
liumiaocn:jenkins liumiao$
使用如下命令即可修改节点信息
liumiaocn:jenkins liumiao$ curl -u "${user_passwd}" -H "${jenkins_crumb}" -X POST -d "@demo/node/xml/agent001.xml" "${jenkins_host_url}/computer/agent001/config.xml"
liumiaocn:jenkins liumiao$ echo $?
0
liumiaocn:jenkins liumiao$
结果确认,可以通过上述的api方式,也可直接通过界面进行确认
节点删除
使用如下命令即可进行节点删除
删除命令:
curl -u "${user_passwd}" -H "${jenkins_crumb}" -X POST "${jenkins_host_url}/computer/agent001/doDelete"
执行日志如下所示:
liumiaocn:jenkins liumiao$ curl -u "${user_passwd}" -H "${jenkins_crumb}" -X POST "${jenkins_host_url}/computer/agent001/doDelete"
liumiaocn:jenkins liumiao$ echo $?
0
liumiaocn:jenkins liumiao$
从下图的Jenkins节点管理页面也可以看到节点agent001已经被删除