问题
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