Skip to content
shellhacks.dev
DevOps

Print CI Environment Variable Names Without Secrets

Print the environment in a CI job with env | cut -d= -f1 | sort to show names only. Filtering by a name like TOKEN misses a URL that holds a password.

1 min read
Summarize in AI

A build behaves differently on the runner, and you want to see its environment without writing credentials into a log everyone can read.

Shell
export API_TOKEN=abc123 DB_URL=postgres://app:[email protected]/app BUILD_ID=42
env | grep -E 'API_TOKEN|DB_URL|BUILD_ID' | grep -viE 'token|secret|password|key'
echo ---
env | grep -E 'API_TOKEN|DB_URL|BUILD_ID' | cut -d= -f1 | sort
Text
DB_URL=postgres://app:[email protected]/app
BUILD_ID=42
---
API_TOKEN
BUILD_ID
DB_URL

Filtering by variable name hides API_TOKEN but passes DB_URL, which carries a password in the value, so the first listing leaks it. Printing only the names, up to the first equals sign, shows which variables exist and avoids the problem for every value, as the second listing shows. CI services mask secrets they know about, but only when the exact string appears, as the GitHub Actions documentation warns, and an encoded or sliced copy is not matched.

Print a single named value when you need it, with a short mask such as the first four characters. Variables that hold multi-line values have continuation lines that cut leaves in place, so use printenv -0 or env -0 when you must be exact. The grep in this example only limits the sample output and is not part of the idiom.

Share

More snippets

DevOps

Run a Script as a Pre-Merge Check in CI

Run a check script as a pre-merge gate and let its exit status decide. Without set -e, a script ends with the status of its last command and hides earlier failures.

1 min read

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.