Originally published on 2015-10-03; fully revised and updated.
Foodcritic is a static analysis tool for Chef cookbooks. This walkthrough is aimed at DevOps engineers maintaining legacy Chef workflows and explains what Foodcritic checks, how to run it from the command line, and how to integrate it into Jenkins so cookbook issues are caught early.

What Foodcritic checks (and what it does not)
Foodcritic analyzes cookbook code and reports rule violations. It is useful for catching structural and quality issues before running Chef on real nodes.
- Style consistency
- Correctness issues
- Syntax and common mistakes
- Best-practice violations
- Deprecation-related warnings
It does not validate business intent. A reported violation is a signal to review context, not an automatic instruction to rewrite code. The original tutorial also notes 47 built-in rules at that time; rule counts may vary by version.
Installation paths used in older environments
The original post shows three installation approaches. Use these primarily for legacy systems where Foodcritic is still part of the toolchain.
| Method | How it works | Typical use case |
|---|---|---|
| RVM + gem | Install Ruby via RVM, then install the foodcritic gem | Multiple Ruby versions on one CI or workstation host |
| System Ruby + gem | Install Ruby from OS package manager, then gem install | Simple host setup with OS-managed Ruby |
| ChefDK bundle | Install ChefDK, which historically bundled Foodcritic | Teams standardizing on Chef’s packaged tooling |
# RVM path (example)
rvm install ruby-2.2.3
gem install foodcritic
# System package path (examples from original post)
sudo apt-get install ruby-2.2.3
# or
sudo yum install ruby-2.2.3
gem install foodcritic
# Historical ChefDK download page
# https://downloads.getchef.com/chef-dk/Code language: PHP (php)
Run Foodcritic locally
Once installed, run Foodcritic against a cookbook directory. Start with a full scan, then tighten policy with tags.
foodcritic --version
foodcritic .
foodcritic -C .
foodcritic -t style .
foodcritic -f correctness .
foodcritic -f any -f ~FC014 .
| Option | Purpose | Example |
|---|---|---|
| -t, –tags TAGS | Run only rules matching tags | foodcritic -t style . |
| -f, –epic-fail TAGS | Fail build when matching tags are found | foodcritic -f correctness . |
| -C, –context | Show matched lines, not only summaries | foodcritic -C . |
| -I, –include PATH | Load custom rule paths | foodcritic -I ./rules . |
| -V, –version | Show installed version | foodcritic -V |
Jenkins integration workflow
A common setup is to run Foodcritic in a Jenkins freestyle job that polls source control and lints cookbooks during each build.
flowchart TD
A[Developer updates cookbook] --> B[Jenkins job starts]
B --> C[Run foodcritic command]
C --> D{Violations found}
D -- no --> E[Build succeeds]
D -- yes --> F[Evaluate fail tags]
F --> G{Matches fail policy}
G -- yes --> H[Build fails]
G -- no --> I[Build passes with warnings]
H --> J[Engineer fixes cookbook]
I --> J
J --> A
#!/usr/bin/env rvm-shell 1.9.3
foodcritic .Code language: JavaScript (javascript)
In Jenkins, this command is typically added under Build Step → Execute shell.
Choose a fail policy your team can maintain
Failing on every warning can create noise. A staged policy is often more effective: fail on high-risk categories first, then tighten over time.
# Fail only on correctness problems
foodcritic -f correctness .
# Fail on any warning except one excluded rule
foodcritic -f any -f ~FC014 .Code language: PHP (php)
| Policy | Command pattern | Trade-off |
|---|---|---|
| Advisory mode | foodcritic . | Low friction, but weak enforcement |
| Targeted enforcement | foodcritic -f correctness . | Catches likely breakage with less noise |
| Strict enforcement | foodcritic -f any … | Highest quality gate, can slow teams if noisy |
Foodcritic supports Cucumber-style tag expressions: https://github.com/cucumber/cucumber/wiki/Tags.
Track warning trends with a Jenkins parser
The original article uses Jenkins Warnings parsing so teams can track lint warning count over time rather than relying only on console logs.
^(FC[0-9]+): (.*): ([^:]+):([0-9]+)$
import hudson.plugins.warnings.parser.Warning
String fileName = matcher.group(3)
String lineNumber = matcher.group(4)
String category = matcher.group(1)
String message = matcher.group(2)
return new Warning(fileName, Integer.parseInt(lineNumber), 'Chef Lint Warning', category, message)Code language: JavaScript (javascript)
- Install Git plugin (if needed) and Warnings-related plugin in Jenkins.
- Create or configure a Jenkins job pointing to your cookbook repository.
- Add an Execute shell step that runs Foodcritic.
- Configure warning parsing for Foodcritic output and save the parser.
- Enable scanning of console logs in post-build actions.
Original references and related links
- http://www.foodcritic.io/
- http://acrmp.github.io/foodcritic/
- https://docs.chef.io/foodcritic.html
- https://downloads.getchef.com/chef-dk/
- https://atom.io/packages/linter-foodcritic
- http://www.slideshare.net/harthoover/rapid-chef-development-with-berkshelf-testkitchen-and-foodcritic
- https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
- http://blog.ninjahideout.com/posts/rvm-improved-support-for-hudson
- https://www.youtube.com/watch?v=ZCfrNvu6nMc
Best practices for legacy Foodcritic usage
- Start with advisory scans, then move to targeted fail tags such as correctness.
- Treat each rule in context; do not auto-fix blindly.
- Track warning trends so refactoring progress is visible across builds.
- Pin and document your Ruby and toolchain versions for reproducible CI behavior.
- Revalidate whether Foodcritic is still the right linter for your current Chef ecosystem.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals