Manage Jenkins with ncf

Jenkins is an excellent application to automatically build/test software projects. We rely on it in Normation to build, test and package Rudder and ncf, for all the OSes and versions we support; resulting in a lot of jobs to manage (currently over 300). Part of Jenkins’ awesomeness is that it has a neat REST API, to fetch, create or copy jobs, or to schedule jobs or restart.

ncf is an open source configuration management framework, designed to be extensible, intuitive and request minimal effort from the user. It is based on “layers”, each being a foundation for the other, and provides generic_methods which are combinable bricks to assemble to perform complex tasks.

To be able to manage our jobs automatically, we implemented in ncf some http request generic_methods, that we use to check if a job exists, and if not create it, based on a job template:

ncf jenkins1

How does that work?

We created templates for the job descriptors, where we need to fill in the name of job, remote repository location, branch to checkout, and optional upstream and downstream projects.

First, we have to check if the job already exists in Jenkins, by performing a GET request on the REST API with the job name as parameter; if Jenkins returns 404, then the job doesn’t exist yet and needs to be created.
This defines a class with the _ok suffix if Jenkins returns a 404 HTTP code. In this case, we need to create the job in Jenkins, with a POST request with the job descriptor on the create URL.

ncf jenkins2

And with these two lines, we can deploy jobs on our Jenkins.

This is a simple example of what we can achieve with ncf, but it opens a lot of opportunities to integrate with tools and systems, now that REST APIs have become ubiquitous – especially in the cloud management ecosystem, to be able manage the lifecycle of virtual machines from within the configuration management system, for example.

Share this post

Share on facebook
Share on twitter
Share on linkedin
Share on print
Share on email
Scroll to Top