Environment
A CI/CD environment is a named deployment target such as dev, staging, or production that holds its own secrets, approval rules, and deployment history.
Understanding CI/CD Environments
What Is a CI/CD Environment and What Does It Add
An environment is more than a label for where code goes. On platforms such as GitHub Actions and GitLab CI it attaches protection rules (required reviewers, wait timers, branch restrictions), environment-scoped secrets, and a deployment history showing who deployed which version and when. That turns a deploy step into an auditable gate.
Typical Promotion Path
Configuration in GitHub Actions
jobs: deploy-staging: runs-on: ubuntu-latest environment: name: staging url: https://staging.payments.internal steps: - name: Deploy env: DB_PASSWORD: ${{ secrets.DB_PASSWORD }} # staging value run: ./deploy.sh staging deploy-production: needs: deploy-staging runs-on: ubuntu-latest environment: name: production # pauses until reviewers approve url: https://api.payments.example.in steps: - name: Deploy env: DB_PASSWORD: ${{ secrets.DB_PASSWORD }} # production value run: ./deploy.sh productionThe same secret name resolves to a different value per environment, so the pipeline code stays identical.
Environment Per Kubernetes Namespace
kubectl create namespace payment-api-stagingkubectl create namespace payment-api-production kubectl apply -f manifests/ -n payment-api-stagingkubectl get deployments -n payment-api-productionNamespaces, or better, separate clusters or accounts for production, give a real isolation boundary behind the pipeline label.
Troubleshooting
| Symptom | Check | What to Look For |
|---|---|---|
| Deploy waiting forever | Required reviewers | Nobody has approved yet |
| Wrong credentials used | Secret scope | Defined at repo level, not environment level |
| No URL on deployment | url in environment block |
Field missing |
TipAdd a 5 to 10 minute wait timer on production in addition to approvals. It gives anyone watching staging time to cancel a bad release.
RememberEnvironment secrets override repository secrets of the same name. Define anything that differs per target at the environment level.
SecurityApproval rules are only as strong as branch protection. If people can push to main directly, they can bypass gates. Require PRs and passing checks, and restrict force pushes.
Common MistakeUsing repository-level secrets for database passwords. Every environment then shares one value, so a compromised dev pipeline reaches production credentials.
Frequently Asked Questions
What does declaring an environment add beyond a deploy target name?
Protection rules (reviewers, wait timers, branch limits), secrets visible only to that environment, and a deployment history. This makes each deploy an auditable gate instead of just a log line.
Should dev, staging, and production share secrets?
No. Scope secrets per environment so a compromised lower environment cannot reach production credentials, and require manual approval only on production to keep feedback fast elsewhere.
How is an environment different from a Kubernetes namespace?
An environment is a CI/CD concept that controls approvals, secrets, and history. A namespace is a cluster boundary. Teams often map one to the other, but production usually deserves a separate cluster or account for stronger isolation.