What is the programmatic way to disconnect a node in Jenkins?

对着背影说爱祢 提交于 2020-05-08 14:55:47

问题


I want to accomplish, through a script using the Jenkins API, the equivalent of manually clicking on the "Disconnect" link on the node management page in Jenkins. I want to add this code to a script I made using the Pipeline scripting plugin.

In other words, as a user with Jenkins admin privileges, do

Manage Jenkins -> Manage Nodes -> Click on a node -> Click on "Disconnect"

As in:

I do not want to do the equivalent of "temporarily mark this node as offline".
That is not useful to me.


回答1:


I don't see anything in the pipeline-model-definition-plugin regarding node management.

So an alternative approach would be to call the disconnect action through the Jenkins API from the pipeline.

  • The Jenkins API for disconnect is:

    http://[jenkins_url]:8080/computer/[slave_name]/doDisconnect?offlineMessage=bye
    
  • Making a Jenkins API call from a pipeline is done through the JENKINS HTTP Request Plugin:

    def response = httpRequest "http://..."
    



回答2:


The hudson.model.Computer class has a disconnect(DisconnectReason) method

Here are the docs for this

In my case, I was able to acquire the Computer instance and disconnect by using Jenkins.instance.getNode(...).getComputer().disconnect(...)



来源:https://stackoverflow.com/questions/44097002/what-is-the-programmatic-way-to-disconnect-a-node-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!