Skip to content
Latchkey

yq -i: Update a Value in Place

yq -i '.path = value' file.yaml assigns a new value at a path and writes the change back to the file.

Bumping an image tag or version is the canonical CI edit. The assignment operator = sets the value, and -i makes the change in place instead of printing to stdout.

What it does

In mikefarah/yq, the = operator assigns a value at the path on its left. By default the result prints to stdout; the -i (or --inplace) flag rewrites the source file instead. Quote string values inside the expression so YAML reads them as strings.

Common usage

Terminal
yq -i '.version = "1.2.3"' chart.yaml
yq -i '.spec.replicas = 3' deployment.yaml
yq -i '.image.tag = strenv(TAG)' values.yaml

Assignment forms

ExpressionEffect
.a = "x"Set a to the string "x"
.a = 3Set a to the number 3
.a.b.c = trueSet a deep path (intermediate maps are created)
.a |= . + 1Update relative to current value
(.a, .b) = "x"Set multiple paths at once
.a = strenv(VAR)Set from an environment variable (as a string)

In CI

To bump a k8s image tag from a pipeline: yq -i '.spec.template.spec.containers[0].image = strenv(IMAGE)' deploy.yaml with IMAGE exported beforehand. Using strenv keeps the value a string; env would let yq parse a tag like 1.10 as a float.

Common errors in CI

Forgetting -i prints the edited document but leaves the file untouched, so the next step sees the old value. Unquoted string values (.version = 1.2.3) are a parse error or become a malformed scalar; quote them. On kislyuk/yq (Python) there is no = assignment and no -i; -i means something else (in-place is -y plus shell redirection), so an "-i" edit silently misbehaving is a sign you are on the wrong yq.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →