Mark Wagner
Mark Wagner

Reputation: 1211

How can I curl the names of all the nodes in a jenkins instance using the Jenkins API?

In the scripts console, i can get information on the nodes with a groovy script like:

for (nodes in Jenkins.instance.getNodes()) {
if (nodes.labelString=="") {
println(nodes.getNodeName()) } }

or

for (nodes in Jenkins.instance.getNodes()) {
   println(nodes.getNodeName()) 
}

Which returns a list of node names for the entire Jenkins instance.

I want to do the same thing with something like:

curl -X get http://<jenkins-endpoint>/nodes/api/json -d json

Does the Jenkins API allow for that or can I only interact with jobs as shown in the link below? https://www.jenkins.io/doc/book/using/remote-access-api/

Upvotes: 1

Views: 2133

Answers (1)

Siddharth Kaul
Siddharth Kaul

Reputation: 972

JenkinsAPI works with almost anything in Jenkins. You can try the following to get a list of all nodes in my case physical computers listed in jenkins instance.

XML

http://jenkinsinstance/computer/api/xml

JSON

http://jenkinsinstance/computer/api/json

This will give you following:

Data snapshot from jenkins instance

1 - class type of the node

2 - Labels you have assigned

3 - The display name of the node.

This is the list of all nodes in jenkins instance.

Upvotes: 2

Related Questions