Cool Features in Node.js Jenkins API

Nimesha Jinarajadasa
2 min readMay 22, 2018

Hi Guys, after several months i got free time to write something. It is all about Node.js & Jenkins. If you have ever used Jenkins(Jenkins which offers continuous integration or continuous delivery for different kinds of projects), you should have some idea about jenkins REST API. You guys ever used the jenkins RESTFul Web services? maybe yes , maybe no. 😛😛

Okay i got something cool for you. I was trying to use jenkins REST API for one of my web project & found cool Jenkins API Client for JS. Actually this library can be used with your Node.js Web Application. Enough Talking Let’s get back to work. Hope you guys have ever worked with Node.js.

If your machine doesn’t contain node.js or npm installed, first install that.
https://nodejs.org/en/

When you install node.js, it comes with npm(NPM is the package manager for Node.js)

Here i’m going to use Express JS Framework to make the things easy. Let’s first install express js framework using NPM.

npm install express-generator -g

Then check whether express is installed properly.

Let’s create our web application named “myapp”.

express --view=pug myapp

Navigate inside newly created Node.js Application

Now install all the dependencies inside package.json file using below command.

Just run the below command which makes debug enable and Node.js Server started.

set DEBUG=myapp:* & npm start

Access http://localhost:3000/ in your browser. Great, we are done with initial Node.js application scaffolding.
Now I'm going to show you how easy to access jenkins through Node.js Jenkins API.
https://www.npmjs.com/package/jenkins-api

Check above URL. All the cool features are there.

Make sure to install jenkins-api first using below command.

npm install jenkins-api
Now just use the API methods in your JS file like below.

Just try out. I can guarantee you that this is going to be very useful.

Originally published at http://printfnimesh.wordpress.com on May 22, 2018.

--

--

Nimesha Jinarajadasa

DevOps Engineer & Advocate @ KodeKloud(Singapore) | Former Senior Software Engineer @ IFS R&D Technology | Top Rated Plus Freelancer @Upwork | Moratuwa Uni Alum