Skip to content

Instantly share code, notes, and snippets.

@samukasmk
Forked from stephenc/gist:3053561
Last active January 2, 2016 23:59
Show Gist options
  • Save samukasmk/8379816 to your computer and use it in GitHub Desktop.
Save samukasmk/8379816 to your computer and use it in GitHub Desktop.

Puppet with Jenkins

Setup Jenkins

With Puppet:

puppet module install rtyler-jenkins
puppet apply -v -e "include jenkins"

Plugins to install

The following Jenkins Plugins should be considered:

  • RVM - manage ruby environments
  • Warnings - capture Puppet-Lint analysis
  • Promoted Builds - manage job lifecycle
  • HTML Publisher - capture RDoc
  • CloudSmith's StackHammer - run tests on metal

RVM

Use RVM to provision Ruby environments. Recommended to use bundler to provision Gemspec.

Here is an example Gemfile file version locked to versions that are known to work with Ruby 1.8.7

source "http://rubygems.org"
gem "puppet", "=2.7.17"
gem "ci_reporter", "=1.7.0"
gem "rspec-puppet", "=0.1.3"
gem "puppet-lint", "=0.1.13"

Note: At this point in time, the latest available puppet-lint gem has some issues with Ruby 1.9

If this is at the root of your module's SCM checkout, you enable and you add an Execute Shell build step with the following:

bundle install

Syntax Check

Add an Execute Shell build step with the following:

for file in $(find . -iname '*.pp');
do
  puppet parser validate \
    --render-as s \
    --modulepath=modules \
    "$file" || exit 1;
done

Static Analysis

Add an Execute Shell build step with the following:

find . -iname *.pp -exec puppet-lint --log-format "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" {}  \;

Add a “Scan for compiler �warnings” Post-Build Action with a Puppet-lint parser in �“Scan console log”

RSpec-Puppet

Configure Rakefile for ci_reporter by adding the following line

require 'ci/reporter/rake/rspec'

Add an Execute Shell build step with the following:

export CI_REPORTS=results
rake ci:setup:rspec spec

Add a “Publish JUnit test result report” Post-Build Action with the following pattern:

**/results/SPEC-*.xml

Documentation

Add an Execute Shell build step with the following:

## Cleanup old docs.
[ -d doc/ ] && rm -rf doc/
## Dummy manifests folder.
! [ -d manifests/ ] && mkdir manifests/
## Generate docs
puppet doc --mode rdoc --manifestdir manifests/ --modulepath ./modules/ --outputdir doc
 
## Fix docs to remove the complete workspace from all file paths.
if [ -d ${WORKSPACE}/doc/files/${WORKSPACE}/modules ]; then
  mv -v "${WORKSPACE}/doc/files/${WORKSPACE}/modules" "${WORKSPACE}/doc/files/modules"
fi
grep -l -R ${WORKSPACE} * | while read fname; do perl -pi -e "s@${WORKSPACE}/@/@g" $fname; done

Add a Publish HTML Reports post build action with the following:

  • HTML directory to archive:

    doc
    
  • Index page(s):

    index.html
    
  • Report title:

    Puppet Docs
    

Useful links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment