Using Node.js To Discover Jenkins On The Network

I’ve just added a new feature to Nestor to discover Jenkins on the network, and as it turned out, it’s pretty simple to do thanks to Node.js Datagram sockets API (hat tip Paul Querna).

Jenkins has a discovery feature as part of its remote access API where it listens on UDP port 33848, and whenever it receives a message, Jenkins will respond with an XML containing the instance’s URL, version number, and slave port information.

So how do you send a UDP message using NodeJS?
Here’s a sample function adapted from Nestor’s lib/service.js:

function sendUdp(message, host, port, cb) {
    var socket = require('dgram').createSocket('udp4'),
        buffer = new Buffer(message);
    socket.on("error", function (err) {
    socket.on("message", function (data) {
        cb(null, data);
    socket.send(buffer, 0, buffer.length, port, host, function (err, message) {
        if (err) {

For Jenkins discovery purpose, send any message to any hostname on port 33848:

sendUdp('Long live Jenkins!', 'localhost', 33848, function () { ... });

and if there’s any Jenkins instance running on localhost, it will respond with an XML like this:



konan cliffano$ nestor discover
Jenkins 1.414 running at http://localhost:8080/

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s