Monday, October 26, 2015

Automatically create Jenkins jobs to run puppet-lint on multiple github repos

If you have multiple git repos for your Puppet modules, as opposed to a single monolithic repo, it is possible to have Jenkins automatically create jobs for all of your repos.  In this example we'll be using Jenkins to create puppet-lint jobs for all git repos in a Github Enterprise organization.  This should be a good starting point towards a more robust continuous integration/delivery pipeline for your Puppet code.

First, install the Job DSL Plugin in your Jenkins instance.  You'll also need to install puppet-lint on your Jenkins master or slave server. 

Next, you'll need to create a Jenkins job that will be used to create all of the other jobs.  This is called the seed job.  More info here.  Create a standard freestyle project and add a Process Job DSL build step.  In the DSL Script box, you'll need to edit this Groovy script to fit your needs.  This was specifically written for Github enterprise, but you should be able to get this to work with regular Github by adjusting the URLs on lines 7 and 19.

This job uses this script to run puppet-lint against each repo.

Once you do a build on the seed job, you'll have a new job created for every git repo in your Github organization.


No comments: