繁体   English   中英

将 Jenkins 节点 label 更改为 REST API

[英]Change Jenkins node label by REST API

我需要从 python 脚本中添加/删除 Jenkins 节点 label。 我尝试使用 REST 请求来做到这一点,但失败了。 这是命令但不起作用:

curl -k -X POST --user [user]@[password] "https://jenkins-automation.itero.net/computer/JL_private/configure?Labels=lb"

请帮助我修复命令或提出其他关于如何从 python 脚本更改 label 的想法。

您不能使用此技术,因为没有用于以这种方式配置节点的configure API。
If you want to update your node configuration via API you should retrive the config.xml of the node using the following API <JENKINS_URL>/computer/<NODE_NAME>/config.xml , then update the config file according to the new settings you want ,最后您可以将更新的 config.xml 发布到相同的 URL 以编程方式更新节点的配置。

config.xml

<slave>
   <name>My First Agent</name>
   <description/>
   <remoteFS>/var/jenkins </remoteFS>
   <numExecutors>5</numExecutors>
   <mode>EXCLUSIVE</mode>
   <retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
   <launcher class="hudson.slaves.JNLPLauncher">
     <workDirSettings>
       <disabled>false</disabled>
       <internalDir>remoting</internalDir>
       <failIfWorkDirIsMissing>false</failIfWorkDirIsMissing>
     </workDirSettings>
     <webSocket>false</webSocket>
    </launcher>
    <label>windows win10 64bit</label>
    <nodeProperties/>
</slave>

在您的情况下,您可以将<label>属性更新为节点 label 所需的新值,并将其发布到上面给出的配置 url 中。

暂无
暂无

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

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