MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

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

Best CodeQL Alternatives for Secure Code Scanning

Replacing CodeQL is not simply a search for another tool that recognizes SQL injection. It is a decision about how much analysis control your team needs, which…

Read More

How to Configure pre-commit for Terraform: Complete DevOps Guide with 15 Practical Use Cases, Commands, Security Checks, and Best Practices

Terraform pre-commit Hooks: Installation, Configuration, TFLint, Trivy, Checkov & CI/CD Guide Learn to configure pre-commit for Terraform with step-by-step commands, terraform fmt, validate, TFLint, Trivy, Checkov, terraform-docs,…

Read More

How to Install and Configure pre-commit on macOS, Windows, and Linux: Complete Step-by-Step Guide

SEO Title: How to Install and Configure pre-commit on Mac, Windows & Linux (2026) Meta Description: Learn how to install and configure pre-commit Git hooks on macOS,…

Read More

Chef Training Roadmap for DevOps Engineers: Course Tracks, Lab Workflow, and Practical Commands

This guide turns a promotional Chef training post into a practical roadmap for engineers. Compare course levels, understand the learning workflow, and use hands-on commands you can run in a lab.

Read More

Jenkins at Scale: Practical References and Admin Cheatsheet

This revised guide upgrades a short 2015 Jenkins link post into an operations-ready reference for teams running Jenkins at scale. It preserves the original links and adds a workflow diagram, comparison table, and practical API/CLI examples.

Read More

Provision an AWS EC2 Instance with Chef (Legacy ChefDK Workflow)

A practical, step-by-step walkthrough for provisioning an AWS EC2 VM using the classic ChefDK and chef-provisioning approach. Includes workflow, commands, recipe examples, and validation checks for legacy environments.

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
28 days ago

Foodcritic can help catch common issues in Chef recipes before they reach production. It is useful to run checks early, so developers can fix problems while the code is still easy to change. Teams should review each warning and decide whether it affects safety, clarity, or consistency. Adding code checks to a test pipeline can help keep recipe quality steady as projects grow. Pairing automated checks with cookbook tests gives teams a stronger way to spot problems before deployment.

Sandeep kumar
Sandeep kumar
1 month ago

Static analysis for Chef recipes is most valuable when its findings become part of the team’s everyday development workflow. I would establish a consistent linting policy, run checks automatically on pull requests, and distinguish critical issues from advisory warnings so developers are not overwhelmed by noise. Another consideration is tool maintenance: before introducing an older analyzer into a modern infrastructure repository, verify its compatibility with the current Ruby environment and Chef versions. Keeping these checks aligned with the supported toolchain helps prevent outdated rules from blocking legitimate infrastructure changes.

2
0
Would love your thoughts, please comment.x
()
x