Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 699
Mark Avatar asked Oct 17 '25 03:10

Mark


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

like image 76
Anthony Sottile Avatar answered Oct 20 '25 04:10

Anthony Sottile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!