yq Command Reference: Flags, Expressions & CI Examples
yq is a portable command-line YAML, JSON, and XML processor.
yq applies jq-style expressions to YAML (and JSON/XML), reading values or editing documents in place. In CI it patches manifests, bumps image tags, and reads config without a YAML parser.
Common flags and usage
- yq '.path' file.yaml: read a value
- -i: edit the file in place
- -o=json / -o=yaml: set the output format
- -r / yq '... | @text': raw, unquoted output
- env(VAR): interpolate an environment variable
- "file1.yaml" "file2.yaml": process multiple documents
Example
shell
yq -i '.image.tag = strenv(IMAGE_TAG)' k8s/deployment.yaml
VERSION=$(yq -r '.version' chart/Chart.yaml)In CI
yq -i patches manifests and Helm charts in place during a release job; strenv(VAR) injects an environment value safely. The Go mikefarah yq and the Python kislyuk yq differ in syntax, so pin the one your scripts target.
Key takeaways
- yq applies jq-style expressions to YAML, JSON, and XML.
- -i edits files in place; strenv() injects env values.
- Pin the Go vs Python yq variant since the syntaxes differ.
Related guides
envsubst Command Reference: Variable Substitution in CIReference for envsubst: substituting environment variables into text, restricting to a SHELL-FORMAT list, and…
sqlite3 Command Reference: Flags, Dot-Commands & CI ExamplesReference for the sqlite3 CLI: running SQL inline, .dump, .read, .mode, -csv, and a CI example that builds an…
getent Command Reference: Databases, Usage & CI ExamplesReference for getent: hosts, passwd, group, the NSS-aware lookup advantage, and a CI example that resolves a…