ripgrep (rg): Fast Recursive Search in CI
ripgrep (rg) recursively searches the current directory for a regex pattern, skipping files listed in .gitignore by default.
rg is the workhorse for "does this string appear anywhere" checks in pipelines. It is fast, but its exit-code behavior surprises people: no match is exit 1, which fails a CI step.
What it does
ripgrep searches the current directory tree for lines matching a regular expression. It honors .gitignore, .ignore, and hidden-file rules by default, which is why it is faster and quieter than grep -r. Output is colorized and grouped by file.
Common usage
rg "TODO" # search cwd recursively
rg "func main" src/ # restrict to a path
rg -i "error" logs/ # case-insensitive
rg -w "id" # whole word only
rg -F "a.b.c" # fixed string, no regexOptions
| Flag | What it does |
|---|---|
| -i / -S | Case-insensitive / smart-case (insensitive unless pattern has uppercase) |
| -w | Match whole words only |
| -F | Treat the pattern as a fixed string, not a regex |
| -v | Invert: show lines that do NOT match |
| -n / -N | Show / hide line numbers |
| -C <n> | Show n lines of context around each match |
| --hidden | Also search hidden files and directories |
| -u / -uu / -uuu | Reduce filtering (ignore .gitignore, then hidden, then binary) |
In CI
rg exits 0 when it finds a match, 1 when it finds none, and 2 on an actual error. To assert a pattern is absent, invert the meaning: ! rg -q "FIXME" fails the step only when FIXME exists. To assert presence, rg -q "VERSION=" succeeds on a hit. Use -q (quiet) so the step gates on exit code without dumping output.
Common errors in CI
"rg: command not found" is the most common failure because ripgrep is not preinstalled on most runners; install it with apt-get install -y ripgrep, brew install ripgrep, or cargo install ripgrep. A step that "fails for no reason" right after an rg call usually hit exit 1 (no match) under set -e; guard it with || true if no-match is acceptable. "regex parse error" means an unescaped metacharacter; add -F for a literal search.