consul kv get: Read Config from Consul KV in CI
consul kv get reads the value at a key, or an entire subtree with -recurse, from the Consul key/value store.
The read side of Consul KV. In a pipeline you pull config at the start of a job; -raw gives you the bare value to assign to a variable.
What it does
consul kv get returns the value stored at a key. -raw prints just the value (no key name or metadata), -recurse returns every key under a prefix, -keys lists key names only, and -detailed adds CreateIndex, ModifyIndex, and flags.
Common usage
consul kv get config/app/log_level
LEVEL=$(consul kv get -raw config/app/log_level)
consul kv get -recurse config/app/
consul kv get -keys config/
consul kv get -detailed config/app/log_levelOptions
| Flag | What it does |
|---|---|
| -raw | Print only the value, no key or metadata |
| -recurse | Return all keys under the given prefix |
| -keys | List key names only (not values) |
| -detailed | Include CreateIndex, ModifyIndex, LockIndex, Flags |
| -separator <s> | Folder separator for -keys listing (default /) |
In CI
Use -raw when capturing a single value into a shell variable so you do not have to strip the key prefix. -keys with -separator is handy for listing the immediate children of a config folder without pulling every value.
Common errors in CI
"Error! No key exists at: <key>" exits non-zero, useful as a guard but fatal if you expected the key; seed it or handle the failure. "Unexpected response code: 403 (Permission denied)" means the token lacks key:read on the prefix. A -recurse on a huge prefix can be slow; scope the prefix tightly.