Home > database >  Change Jenkins node label by REST API
Change Jenkins node label by REST API

Time:11-25

I need to add/delete Jenkins node label from python script. I tried to do it using REST request but failed with it. This is the command but not works:

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

Please help me to fix the command or suggest other idea of how to change label from python script.

CodePudding user response:

You can't use this technique as there is no configure API for configuring the node in this way.
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, and finally you can POST an updated config.xml to the same URL to programmatically update the configuration of a node.

Example of the 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>

In your case you can just update the <label> attribute to the new value you want for the node label, and post it to the configuration url given above.

  • Related