How to Set Environment-Specific Feature Flag Values
Scope flag values per environment so staging can preview a feature while production stays off.
Most flag tools model separate environments (dev, staging, production) each with their own values. CI selects the environment key for the target so the same code reads the right state.
Steps
- Define per-environment values for the flag.
- Store one environment key per environment as a secret.
- Select the key in CI based on the deploy target.
Per-environment values
flags.yaml
flags:
new-checkout:
environments:
staging: { defaultVariation: true }
production: { defaultVariation: false }Pick the environment in CI
.github/workflows/deploy.yml
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.target }}
env:
FLAG_ENV_KEY: ${{ secrets[format('FLAG_KEY_{0}', inputs.target)] }}
steps:
- run: ./deploy.shGotchas
- A staging-only flag left on in the shared code path can leak into production if the key is wrong.
- Keep environment names consistent between the flag tool and your CI environments.
Related guides
How to Manage Feature Flag Config as CodeKeep feature flag definitions in a version-controlled file and sync them from CI so flag changes go through r…
How to Write Feature Flag Targeting RulesTarget a feature flag at specific users, plans, or attributes with rules so a feature reaches only the intend…