CI Environment Variables and Secrets
You'll learn how to securely manage sensitive configuration like API keys and database URLs in your CI pipeline without hardcoding them or exposing them in your repository.
The Security Challenge
When your E2E tests run in CI (like GitHub Actions), they often need access to sensitive data: staging API endpoints, authentication tokens, test database credentials, or third-party service keys. Hardcoding these values directly in your test files or committing them to version control creates serious security risks—anyone with repo access sees your secrets.
Environment Variables in CI
CI platforms let you define encrypted secrets in their settings UI. These become environment variables at runtime, accessible to your tests without appearing in your codebase.
In GitHub Actions, you reference secrets like this:
# .github/workflows/e2e.yml
env:
API_BASE_URL: ${{ secrets.STAGING_API_URL }}
TEST_USER_TOKEN: ${{ secrets.TEST_AUTH_TOKEN }}
DATABASE_URL: ${{ secrets.TEST_DB_CONNECTION }}
Your Playwright config then reads these:
// playwright.config.js
export default {
use: {
baseURL: process.env.API_BASE_URL || 'http://localhost:3000',
},
};
Think of It Like Hotel Key Cards
Imagine CI as a hotel: each test run is a guest checking in. Instead of engraving the master key (your production credentials) on the door for everyone to see, the hotel (CI platform) issues temporary key cards (environment variables) that only work during that stay. The master key stays locked in the safe (CI secrets storage).
Key Takeaway: Store sensitive values as encrypted secrets in your CI platform's settings, inject them as environment variables at runtime, and never commit credentials to your repository—this keeps your pipeline secure while giving tests the access they need.