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.

 
17
Kudos
 
17
Kudos

Now read this

Our Role in an Automated World

There is a recurring story about automation told by those looking at tech from the outside. It is a popular anecdote, and goes something like this: Lisa is a developer at Initrode. She spent most of her day in databases and spreadsheets,... Continue →