Detecting Chef upload failures with Jenkins

Our Chef workflow at Essess looks like this:

We’re using hosted Chef, so we assumed this would be seamless. Nope. A developer would push, the jobs would trigger and Jenkins would report back green. Later on they would notice that the cookbook was still pinned to an old version in the environment. Returning to Jenkins, we see something like this in the job’s console output log:

Jenkins log

Well, that didn’t go as expected. You would think that if there was an upload failure we would get a non-0 exit code and Jenkins would report the build as failed. Not so. We use knife cookbook upload --all --force --environment ${env} to upload all cookbooks installed via berkshelf. env here is a Jenkins parameter.

Okay, so what do we do now? Here’s one solution, the one I implemented.

Using the Jenkins Warnings plugin, I created a custom compiler warning for this. Once you install this plugin, go to /configure and look for the Compiler Warnings section. Add an entry like this:

Compiler warning config

Now, go back to your job that is uploading to Chef, and add a Post-Build step, choosing Scan for compiler warnings from the dropdown. Click Add under Scan console log and choose Chef Upload Failure as your parser. You’ll end up with this:

Post-build config

and a nice graph on the job detail page to show you how often this is happening.

Upload warning graph

Now your build will not pass when upload errors occur.


Now read this

Lessons learned running a DevOps meetup

I’ve been organizing the Boston DevOps meetup for almost two years now. When the organizer spot opened up I jumped at the chance. My experience DevOps-ing along in smaller organizations gave me a pretty narrow view of the movement and I... Continue →