Environment Variables and Secrets
You'll learn how to safely manage configuration and sensitive data in CI builds without hardcoding values or exposing credentials.
The Core Idea
When your CI pipeline builds and tests code, it often needs configuration values (like API endpoints, database URLs) and secrets (like passwords, API keys, tokens). Hardcoding these in your codebase is dangerous—it exposes credentials and makes it hard to change settings between environments (dev, staging, production).
The solution: environment variables and secret management. Your CI server injects values into the build environment at runtime, keeping sensitive data out of version control.
How It Works
Environment variables are key-value pairs available to your build process. Your CI platform (from lesson 636) lets you define these in its UI or configuration file. At build time, the CI agent (lesson 640) makes them available to your code and scripts.
Secrets are a special category—passwords, tokens, private keys—that require extra protection. CI platforms encrypt secrets at rest and mask them in build logs.
The Pattern
- Define variables in your CI platform's settings (e.g.,
DATABASE_URL,API_KEY) - Mark sensitive values as secrets (encrypted, hidden from logs)
- Reference them in your build configuration file (lesson 638) using platform-specific syntax
- Access them in your code like any environment variable
Think of it like a locked box: your code knows where to look for the key, but the actual key is securely stored elsewhere and only handed over at the right moment.
Key Takeaway: Environment variables and secrets let you configure CI builds dynamically and securely, keeping sensitive data encrypted and out of your codebase while still making it available when builds run.