0

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/

Mark Wagner
  • 1,011
  • 6
  • 11

1 Answers1

1

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.

Siddharth Kaul
  • 871
  • 10
  • 20
  • Hats off! I didn't know that this API exists. Too bad that it isn't mentioned on the main API page `http://jenkins/api`. Do you know of a reference page containing a list of all available APIs? – Gerold Broser Aug 06 '21 at 19:24
  • 1
    No i am not aware of any reference page containing all available API :( – Siddharth Kaul Aug 07 '21 at 14:33
  • Ah...there's the sentence at the beginning of every `/api` page: "_Many objects of Jenkins provide the remote access API. They are available at `/.../api/` where "`...`" portion is the object for which you'd like to access._". So, it's always `.../` + `/api.` Well...RTFM to myself. – Gerold Broser Aug 10 '21 at 12:17