API to create/manage nodes

3,567 views
Skip to first unread message

Chaitanya Jandhyala

unread,
Jan 7, 2012, 5:06:30 PM1/7/12
to jenkins...@googlegroups.com
Hi,

Does Jenkins have an API to create/Manage nodes. To be specific I am looking for the api to be able to

1) create the nodes
2) query the configuration of the nodes
3) Check whether its online or offline and
4) Disconnect and launch the agent

Any pointers will be appreciated.

Thanks and regards,
CJ

Mark Waite

unread,
Jan 7, 2012, 5:59:54 PM1/7/12
to jenkins...@googlegroups.com
I'm not aware of an API to create new slave nodes.  I think there was a previous discussion on the mailing list about creating slave nodes from the API and there did not seem to be a way to create new slave nodes from the API. 
 
When I run the Jenkins command line interface (CLI) from my machine, it lists the following node control APIs (no create-node command):
 
connect-node (Reconnect to a node)
delete-node (Deletes a node)
disconnect-node (Disconnects from a node)
offline-node (Stop using a node for performing builds)
online-node (Resume using a node for performing builds)
wait-node-offline (Wait for a node to become offline)
wait-node-online (Wait for a node to become online)
 
You can read more about using the command line interface on the Jenkins Wiki.
 
There is lots of information about the slave nodes available from the API URL if you're willing to use XML, JSON, or Python.  Try appending "/api/" to any of the web page URL's and it will give you a very nice page introducing you to those APIs.  Clickable links within that page will let you see the various outputs in your web browser.
 
For example, I can see lots of node information on http://mwaite1:8080/computer/api/xml?depth=1 .  That includes online / offline status, various health attributes (number of executors, temporary space, disc space, etc.), and more.
 
Mark Waite

Alexander Voss

unread,
Jan 15, 2012, 5:29:33 PM1/15/12
to Jenkins Users
Dear all,

like Chaitanya I am looking for a way to create a slave node through a
script. I have looked around the built-in API help and the web but am
still not sure how to go about this. There is some code in jenkinsapi
(http://pypi.python.org/pypi/jenkinsapi) that posts to /doCreateItem
but I am not entirely sure I understand what the data being sent there
means. It would help if I could get a dump of a configuration but
there does not seem to be a way to get this - unlike for jobs or
users. I need to configure the advanced options of the launch method
configuration and would like to know what the field names for this
are.

Any pointers very welcome.

Best wishes,

Alex

On Jan 7, 10:59 pm, Mark Waite <markwa...@yahoo.com> wrote:
> I'm not aware of an API to create new slave nodes.  I think there was a previous discussion on the mailing list about creating slave nodes from the API and there did not seem to be a way to create new slave nodes from the API.
>
> When I run the Jenkins command line interface (CLI) from my machine, it lists the following node control APIs (no create-node command):
>
> connect-node (Reconnect to a node)
> delete-node (Deletes a node)
> disconnect-node (Disconnects from a node)
> offline-node (Stop using a node for performing builds)
> online-node (Resume using a node for performing builds)
> wait-node-offline (Wait for a node to become offline)
> wait-node-online (Wait for a node to become online)
>
> You can read more about using the command line interface on the Jenkins Wiki.
>
> There is lots of information about the slave nodes available from the API URL if you're willing to use XML, JSON, or Python.  Try appending "/api/" to any of the web page URL's and it will give you a very nice page introducing you to those APIs.  Clickable links within that page will let you see the various outputs in your web browser.
>
> For example, I can see lots of node information onhttp://mwaite1:8080/computer/api/xml?depth=1 .  That includes online / offline status, various health attributes (number of executors, temporary space, disc space, etc.), and more.
>
> Mark Waite
>
>
>
>
>
>
>
> >________________________________
> > From: Chaitanya Jandhyala <chaitanya.jandhy...@gmail.com>

Alexander Voss

unread,
Jan 15, 2012, 5:53:52 PM1/15/12
to Jenkins Users

Hi again,

just a quick note to say I will be trying to solve the immediate
problem I am having with the Swarm plugin (https://wiki.jenkins-ci.org/
display/JENKINS/Swarm+Plugin). Perhaps this helps others as well?

Cheers,

Alex

On Jan 15, 10:29 pm, Alexander Voss <alexvoss...@gmail.com> wrote:
> Dear all,
>
> like Chaitanya I am looking for a way to create a slave node through a
> script. I have looked around the built-in API help and the web but am
> still not sure how to go about this. There is some code in jenkinsapi
> (http://pypi.python.org/pypi/jenkinsapi) that posts to /doCreateItem
> but I am not entirely sure I understand what the data being sent there
> means. It would help if I could get a dump of a configuration but
> there does not seem to be a way to get this - unlike for jobs or
> users. I need to configure the advanced options of the launch method
> configuration and would like to know what the field names for this
> are.
>
> Any pointers very welcome.
>
> Best wishes,
>
> Alex
>
> On Jan 7, 10:59 pm, Mark Waite <markwa...@yahoo.com> wrote:
>
>
>
>
>
>
>
> > I'm not aware of an API to create new slavenodes.  I think there was a previous discussion on the mailing list about creating slavenodesfrom the API and there did not seem to be a way to create new slavenodesfrom the API.
>
> > When I run the Jenkins command line interface (CLI) from my machine, it lists the following node control APIs (no create-node command):
>
> > connect-node (Reconnect to a node)
> > delete-node (Deletes a node)
> > disconnect-node (Disconnects from a node)
> > offline-node (Stop using a node for performing builds)
> > online-node (Resume using a node for performing builds)
> > wait-node-offline (Wait for a node to become offline)
> > wait-node-online (Wait for a node to become online)
>
> > You can read more about using the command line interface on the Jenkins Wiki.
>
> > There is lots of information about the slavenodesavailable from the API URL if you're willing to use XML, JSON, or Python.  Try appending "/api/" to any of the web page URL's and it will give you a very nice page introducing you to those APIs.  Clickable links within that page will let you see the various outputs in your web browser.
>
> > For example, I can see lots of node information onhttp://mwaite1:8080/computer/api/xml?depth=1 .  That includes online / offline status, various health attributes (number of executors, temporary space, disc space, etc.), and more.
>
> > Mark Waite
>
> > >________________________________
> > > From: Chaitanya Jandhyala <chaitanya.jandhy...@gmail.com>
> > >To: jenkins...@googlegroups.com
> > >Sent: Saturday, January 7, 2012 3:06 PM
> > >Subject: API to create/managenodes
>
> > >Hi,
>
> > >Does Jenkins have an API to create/Managenodes. To be specific I am looking for the api to be able to

grayaii

unread,
Jan 16, 2012, 9:20:45 AM1/16/12
to jenkins...@googlegroups.com
You can read my post here:
http://jenkins.361315.n4.nabble.com/Event-Trigger-when-job-gets-put-on-queue-td4021230.html#a4024248
comment

Like you, I'm creating slaves via the Swarm Plugin. It works pretty good
and so far I've had no issues using it.


--
View this message in context: http://jenkins.361315.n4.nabble.com/API-to-create-manage-nodes-tp4274306p4299622.html
Sent from the Jenkins users mailing list archive at Nabble.com.

Viliam Aboši

unread,
Feb 5, 2013, 3:36:18 AM2/5/13
to jenkins...@googlegroups.com, georg...@rsa.com
I know this "thread" is old, but in case someone has the same problem with creating nodes via a script here is my solution (that considering how easy it is in the end took me an awfully lot of time to figure out):

Jenkins-CLI has an option to run groovy scripts:

java -jar path/to/jenkins-cli.jar -s http://localhost:8080 groovy path/to/script

script:

import jenkins.model.*
import hudson.model.*
import hudson.slaves.*
Jenkins.instance.addNode(new DumbSlave("test-script","test slave description","C:\\Jenkins","1",Node.Mode.NORMAL,"test-slave-label",new JNLPLauncher(),new RetentionStrategy.Always(),new LinkedList())) 

(see docs for other options: http://javadoc.jenkins-ci.org/)

You can also run an interactive groovy shell with 

java -jar jenkins-cli.jar -s http://localhost:8080 groovysh

But any attempts to "feed" it a single command were unsuccessful in my case.



Dňa pondelok, 16. januára 2012 15:20:45 UTC+1 grayaii napísal(-a):

Kannan Manickam

unread,
Jun 28, 2013, 5:54:34 AM6/28/13
to jenkins...@googlegroups.com, georg...@rsa.com
I have implemented a Jenkins Ruby API Client here: https://github.com/arangamani/jenkins_api_client

The documentation can be found here for creating node via the API: http://rubydoc.info/gems/jenkins_api_client/0.12.1/JenkinsApi/Client/Node:create_dump_slave

Alex Henderson

unread,
Jan 21, 2014, 7:48:55 AM1/21/14
to jenkins...@googlegroups.com, georg...@rsa.com
This worked perfectly, thank you very much! I wish there was a way to bring this to the top of search results.

Now I need to figure out how to dynamically create jobs...

Manish Singh

unread,
Sep 1, 2014, 11:25:43 AM9/1/14
to jenkins...@googlegroups.com, georg...@rsa.com
Any ideas on how to create a dumb node which connects using ssh for Linux using a solution similar to above?
Reply all
Reply to author
Forward
0 new messages