Pipeline guide
CI/CD Best Practices
Written by Nitish Maurya
Founder of CloudOpsync. Hands-on with Linux servers, AWS, CI/CD, Docker and monitoring for production teams.
By Nitish Maurya, founder of CloudOpsyncPublished Updated 3 min read
Build once, promote the same artifact
The most common source of 'it worked in staging' incidents is rebuilding the application separately for each environment. A different build moment can pull a different dependency version, a different base image, or a different environment value baked in at build time. Build one artifact per commit (a container image, a compiled bundle or a release archive), tag it with the commit SHA, and promote that exact artifact from staging to production. Environment-specific settings belong in runtime configuration, not in the build.
- Commit lock files (package-lock.json, pnpm-lock.yaml, poetry.lock) and install with the frozen or ci flag.
- Pin base images by version, and by digest for critical services.
- Tag artifacts with the commit SHA; use human-friendly tags only as extra labels.
- Keep secrets and per-environment URLs out of the build output.
Keep the feedback loop short
A pipeline that takes 40 minutes gets bypassed. Split checks by cost: linting, type checks and unit tests on every push; integration tests on pull requests; slower end-to-end suites before release or on a schedule. Cache dependency installs and Docker layers, run independent jobs in parallel, and fail fast so developers see the first real error within a few minutes. Track pipeline duration as a number the team owns, the same way it owns application latency.
- Cache package manager stores and Docker build layers between runs.
- Run lint, test and build as parallel jobs where they do not depend on each other.
- Quarantine flaky tests with an owner and a deadline instead of re-running until green.
Handle secrets as a pipeline responsibility
CI systems see production credentials, so they need the same care as production servers. Store secrets in the CI provider's encrypted store or a secrets manager, scope them to the environments that need them, and prefer short-lived credentials such as OpenID Connect federation to AWS, Azure or Google Cloud over long-lived access keys. Make sure scripts never echo secrets, and restrict who can modify workflows that run with production access.
- Use environment-scoped secrets with required reviewers for production.
- Replace static cloud keys with OIDC role assumption where the provider supports it.
- Run a secret scanner on pushes so leaked keys are caught before they spread.
Gate production on health, not hope
A deploy is not finished when the upload succeeds; it is finished when the new version is serving real traffic correctly. Add a post-deploy step that calls a health endpoint, checks key routes and confirms the expected version is live. For higher-traffic systems, roll out gradually (a share of instances or traffic first) and watch error rate and latency before continuing. Manual approval is useful for regulated or high-risk changes, but it should complement automated checks, not replace them.
Make rollback boring
Rollback should be one documented command or one click that redeploys the previous artifact, and it should be practised before an incident needs it. Because the previous artifact already exists, rolling back is fast. Database migrations need extra care: write them to be backward compatible (expand first, contract in a later release) so the previous application version still works against the new schema.
- Keep at least the last few production artifacts available for instant redeploy.
- Separate schema changes into expand and contract steps across releases.
- Record who deployed what and when, so incidents start from facts.
Measure whether the pipeline is helping
The four DORA measures give a simple, widely used view of delivery health: how often you deploy, how long a change takes to reach production, how often deploys cause failures, and how quickly you recover. You do not need a dashboard product to start; a spreadsheet updated from deploy logs each week is enough to show whether pipeline changes are making releases faster and safer.
Related services
Continue from guide to implementation.
Consultation
Turn the guide into a production-ready DevOps plan.
Share your stack, risk level, and delivery goal. You will get a practical scope conversation instead of a generic sales pitch.
