Skip to main content

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

flowchart LR A[dev: auto deploy] --> B[staging: auto on merge] B --> C{Approval and wait timer} C --> D[production] classDef env fill:#326CE5,color:#FFFFFF classDef gate fill:#8B5CF6,color:#FFFFFF classDef prod fill:#10B981,color:#FFFFFF class A,B env class C gate class D prod

Configuration in GitHub Actions

YAML
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 production

The same secret name resolves to a different value per environment, so the pipeline code stays identical.

Environment Per Kubernetes Namespace

Bash
kubectl create namespace payment-api-staging
kubectl create namespace payment-api-production
kubectl apply -f manifests/ -n payment-api-staging
kubectl get deployments -n payment-api-production

Namespaces, 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
Tip

Add a 5 to 10 minute wait timer on production in addition to approvals. It gives anyone watching staging time to cancel a bad release.

Remember

Environment secrets override repository secrets of the same name. Define anything that differs per target at the environment level.

Security

Approval 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 Mistake

Using 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.

Found a mistake, an outdated step or a broken link?