我需要从 python 脚本添加/删除 Jenkins 节点标签。我尝试使用 REST 请求来执行此操作,但失败了。 这是命令,但不起作用:
curl -k -X POST --user [user]@[password] "https://jenkins-automation.itero.net/computer/JL_private/configure?Labels=lb"
请帮助我修复该命令或提出有关如何从 python 脚本更改标签的其他想法。
最佳答案
您不能使用此技术,因为没有 configure
用于以这种方式配置节点的 API。
如果您想通过 API 更新节点配置,您应该检索 config.xml
使用以下 API <JENKINS_URL>/computer/<NODE_NAME>/config.xml
的节点,然后根据您想要的新设置更新配置文件,最后您可以将更新后的 config.xml POST 到同一 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>
属性为您想要的节点标签的新值,并将其发布到上面给出的配置 url。
关于python - 通过REST API更改Jenkins节点标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70094135/