Jenkins基础:API:9:使用API更新删除节点

在上篇文章中介绍了在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 directoryAgent的远程数据目录/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已经被删除
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值