Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Foodcritic for Chef Cookbooks: Practical Linting and Jenkins CI for Legacy Pipelines

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.

Chef code analysis using Foodcritic

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.

MethodHow it worksTypical use case
RVM + gemInstall Ruby via RVM, then install the foodcritic gemMultiple Ruby versions on one CI or workstation host
System Ruby + gemInstall Ruby from OS package manager, then gem installSimple host setup with OS-managed Ruby
ChefDK bundleInstall ChefDK, which historically bundled FoodcriticTeams 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 .
OptionPurposeExample
-t, –tags TAGSRun only rules matching tagsfoodcritic -t style .
-f, –epic-fail TAGSFail build when matching tags are foundfoodcritic -f correctness .
-C, –contextShow matched lines, not only summariesfoodcritic -C .
-I, –include PATHLoad custom rule pathsfoodcritic -I ./rules .
-V, –versionShow installed versionfoodcritic -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)
PolicyCommand patternTrade-off
Advisory modefoodcritic .Low friction, but weak enforcement
Targeted enforcementfoodcritic -f correctness .Catches likely breakage with less noise
Strict enforcementfoodcritic -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

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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

How to Install ChefDK on RHEL, Ubuntu, macOS, and Windows (Legacy-Friendly Guide)

Learn a practical, cross-platform process to install ChefDK and verify it correctly on RHEL/CentOS, Ubuntu, macOS, and Windows. This guide also helps you decide when ChefDK is still appropriate versus Chef Workstation.

Read More

Chef Command-Line Reference: Essential chef-solo, chef-client, and Knife Workflows

A task-oriented reference for frequently used Chef and Knife commands, from cookbook scaffolding to node bootstrap and run-list management. Includes workflow guidance and copy-ready command examples.

Read More

Automating Chef Cookbook README Files with Knife and Community Plugins

Reusable Chef cookbooks often outgrow their documentation. This guide shows how to bootstrap README files with Knife, compare plugin-based generation options, and keep docs in sync as cookbooks evolve.

Read More

What is Chef and use cases of Chef?

What is Chef? Chef is a powerful configuration management and automation tool that allows organizations to manage and automate the deployment, configuration, and maintenance of infrastructure. It…

Read More

What is Chef Compliance and use cases of Chef Compliance?

What is Chef Compliance? Chef Compliance is a component of Chef, an automation platform used for configuration management, application deployment, and infrastructure as code (IaC). Chef Compliance…

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
2
0
Would love your thoughts, please comment.x
()
x