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

Viewed 5976

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:

Mange Node Page

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

2 Answers

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(...)

Related