59 lines
2.8 KiB
Markdown
59 lines
2.8 KiB
Markdown
# ADR-0002: Branch Name as the Sole Environment Selector
|
|
|
|
**Status:** Accepted
|
|
**Category:** PATTERN
|
|
**Date decided:** Project inception
|
|
**Date documented:** 2026-05-12
|
|
|
|
## Context
|
|
|
|
Each Meesho service needs to deploy to different environments (staging, production, integration, feature). A naive approach would let each service declare its target environment in config, but this creates a risk: a misconfigured service could accidentally deploy to production from a feature branch, or fail to promote through the standard develop → stg → main → prd path.
|
|
|
|
## Decision
|
|
|
|
`cicd_environment` is derived entirely and deterministically from the branch name. No per-service environment configuration exists. The mapping is:
|
|
|
|
| Branch | PR target | `cicd_environment` |
|
|
|---|---|---|
|
|
| `main` / `master` / `gcp-main` | — | `prd` |
|
|
| `develop` | — | `stg` |
|
|
| any | `main` | `int` |
|
|
| any | `develop` | `ftr` |
|
|
| `hotfix/*` | — | `prd` (sonar + tests skipped) |
|
|
|
|
## Alternatives Considered
|
|
|
|
- **Per-service environment configuration**: Rejected because it creates a class of misconfiguration bugs (wrong env in config.yaml → wrong deploy target) and makes it impossible to enforce the standard branch promotion strategy uniformly.
|
|
- **Environment as a Jenkins parameter**: Rejected because it relies on the engineer picking the right environment at trigger time — error-prone and not auditable.
|
|
|
|
## Consequences
|
|
|
|
**Positive:**
|
|
- Services cannot accidentally deploy to prd from a feature branch — the branch IS the environment contract.
|
|
- Standard develop → stg → main → prd promotion is enforced uniformly across all services.
|
|
- Environment logic lives in one place (`constructParam.groovy`) — easy to audit and change centrally.
|
|
|
|
**Negative:**
|
|
- Teams with non-standard branch strategies (e.g., release/* branches) cannot use the standard pipeline without DevOps involvement.
|
|
- The hotfix path (prd with sonar skipped) requires following the `hotfix/*` naming convention exactly.
|
|
|
|
**Neutral:**
|
|
- The `int` and `ftr` environments are determined by PR target, not branch name — this is the one case where branch name alone is insufficient.
|
|
|
|
## Constraints
|
|
|
|
Meesho's deployment policy required a standard promotion path. Allowing per-service environment configuration would have made it impossible to enforce this uniformly across 100+ services.
|
|
|
|
## Current Assessment
|
|
|
|
**Still appropriate** — no changes needed.
|
|
|
|
## Related Decisions
|
|
|
|
- [ADR-0001: Single Shared Library](0001-single-shared-library-for-all-services.md) — The shared library enforces this mapping; per-service Jenkinsfiles could override it.
|
|
|
|
## Notes
|
|
|
|
- Key file: `src/com/meesho/utilities/constructParam.groovy` — environment mapping logic
|
|
- PR context is detected via `env.CHANGE_ID` (set by GitHub Branch Source plugin), not by `env.BRANCH_NAME =~ /PR-/`
|