CI/CD Quick Reference
Everything you need day‑to‑day – automation, pipelines, and tooling.
What is CI/CD?
Continuous Integration (CI)
- Automatically build and test code on every push
- Catches bugs early
- Merges changes frequently
- Key principle: "Integrate early, integrate often"
Continuous Delivery (CD)
- Automatically deploy to staging after CI passes
- Code is always in a deployable state
- Manual approval for production
Continuous Deployment
- Every change that passes CI is deployed to production automatically
- No manual intervention
- Requires robust testing and monitoring
CI/CD Benefits
- Faster time to market
- Reduced risk
- Higher quality
- Better collaboration
- Automated and repeatable process
CI/CD Pipeline Stages
1. Source
- Code is pushed to version control
- Triggers the pipeline (GitHub, GitLab, Bitbucket)
2. Build
- Compile code
- Install dependencies
- Package artifacts (JAR, WAR, Docker image)
3. Test
- Unit tests
- Integration tests
- End‑to‑end tests
- Code quality (SonarQube, ESLint)
- Security scanning (SAST, DAST)
4. Deploy (Staging)
- Deploy to staging environment
- Run smoke tests
- User acceptance testing (UAT)
5. Deploy (Production)
- Manual approval (Delivery)
- Automatic (Deployment)
- Rolling or blue‑green deployment
- Canary releases
6. Monitor
- Application performance monitoring (APM)
- Log aggregation
- Error tracking
- Rollback on failure
CI/CD Tools
CI Tools
- Jenkins – Open‑source, highly configurable
- GitHub Actions – Native GitHub CI/CD
- GitLab CI – Integrated with GitLab
- CircleCI – Cloud‑based, fast
- Travis CI – Simple, cloud‑based
- TeamCity – JetBrains, enterprise
- Bamboo – Atlassian, Jira integration
- Azure DevOps – Microsoft
- Bitbucket Pipelines – Bitbucket native
CD Tools
- ArgoCD – GitOps Kubernetes deployment
- Flux – GitOps for Kubernetes
- Spinnaker – Netflix, multi‑cloud
- Octopus Deploy – .NET ecosystem
- Jenkins – Also supports CD
- GitHub Actions – Also supports CD
GitHub Actions
Workflow Structure
name: CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install
- run: npm test
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/download-artifact@v4
with:
name: dist
- run: echo "Deploying to production..."
Common GitHub Actions
actions/checkout– Checkout repositoryactions/setup-node– Setup Node.jsactions/setup-python– Setup Pythonactions/setup-java– Setup Javaactions/cache– Cache dependenciesactions/upload-artifact– Upload build artifactsactions/download-artifact– Download artifactsactions/deploy– Deploy to various servicesdocker/login-action– Login to Docker registrydocker/build-push-action– Build and push Docker images
Secrets
// In GitHub repo: Settings → Secrets and variables → Actions // Use secrets in workflow steps: - run: echo "API key: ${{ secrets.API_KEY }}"
GitLab CI
// .gitlab-ci.yml
image: node:20
stages:
- build
- test
- deploy
variables:
NODE_VERSION: '20'
cache:
paths:
- node_modules/
build:
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- dist/
test:
stage: test
script:
- npm test
deploy:
stage: deploy
script:
- echo "Deploying..."
only:
- main
CircleCI
// .circleci/config.yml
version: 2.1
jobs:
build:
docker:
- image: cimg/node:20.0
steps:
- checkout
- run: npm install
- run: npm test
- run: npm run build
- persist_to_workspace:
root: .
paths: [dist]
deploy:
docker:
- image: cimg/node:20.0
steps:
- attach_workspace:
at: .
- run: echo "Deploying..."
workflows:
version: 2
build_and_deploy:
jobs:
- build
- deploy:
requires: [build]
filters:
branches:
only: main
Jenkins
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/user/repo.git'
}
}
stage('Build') {
steps {
sh 'npm install'
sh 'npm run build'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sh 'echo "Deploying to production..."'
}
}
}
post {
always {
cleanWs()
}
}
}
Jenkinsfile (Scripted Pipeline)
node {
stage('Checkout') {
git 'https://github.com/user/repo.git'
}
stage('Build') {
sh 'npm install && npm run build'
}
stage('Test') {
sh 'npm test'
}
stage('Deploy') {
if (env.BRANCH_NAME == 'main') {
sh 'echo "Deploying..."'
}
}
}
Deployment Strategies
Rolling Update
- Updates instances gradually (zero downtime)
- Replaces old instances with new ones
- Pros: Simple, no downtime
- Cons: Slow, complex rollback
Blue‑Green Deployment
- Two identical environments
- Blue (current), Green (new)
- Switch traffic when ready
- Pros: Instant rollback, zero downtime
- Cons: Double infrastructure cost
Canary Deployment
- Roll out to small percentage of users first
- Monitor for errors
- Gradually increase traffic
- Pros: Low risk, real‑world testing
- Cons: Complex, requires monitoring
Feature Flags
- Toggle features on/off without deployment
- Separate deployment from release
- Pros: Very low risk, A/B testing
- Cons: Requires flag management tool
A/B Testing
- Show different versions to different users
- Measure metrics (conversion, engagement)
- Pros: Data‑driven decisions
- Cons: Complex implementation
Rollback
- Revert to previous version
- Automatic rollback on failure
- Critical for reliability
Pipeline as Code
- Benefits: Version control, collaboration, auditability
- Tools: GitHub Actions YAML, GitLab CI YAML, CircleCI config, Jenkinsfile
- Best practice: Keep pipeline code in the same repository as source code
Best Practices
- Keep builds fast – parallelise, cache dependencies
- Run tests in CI – all tests must pass before merging
- Use branch protection – require CI to pass before merging
- Use environment variables – for configuration (not hardcoded)
- Use secrets – never commit secrets
- Build once, deploy many – use the same artifact across environments
- Automate everything – builds, tests, deployments
- Monitor deployments – track success/failure rates
- Rollback on failure – automatically or with a single command
- Use immutable artifacts – each build has a unique version
- Keep pipeline simple – avoid complex logic
- Use small, frequent commits – easier to debug and rollback
- Secure CI/CD – limit access to secrets, audit changes
- Document the pipeline – so team understands it
📌 Quick Reference
CI: Build + Test on every push
CD: Deploy to staging (delivery) or production (deployment)
Pipeline stages: Source → Build → Test → Deploy → Monitor
Tools: Jenkins, GitHub Actions, GitLab CI, CircleCI, ArgoCD
Deployment strategies: Rolling, Blue‑Green, Canary, Feature Flags
Best practices: fast builds, automate all, monitor, rollback, immutable artifacts
CD: Deploy to staging (delivery) or production (deployment)
Pipeline stages: Source → Build → Test → Deploy → Monitor
Tools: Jenkins, GitHub Actions, GitLab CI, CircleCI, ArgoCD
Deployment strategies: Rolling, Blue‑Green, Canary, Feature Flags
Best practices: fast builds, automate all, monitor, rollback, immutable artifacts