A CI/CD pipeline is an automated workflow that enables Continuous Integration (CI) and Continuous Deployment/Delivery (CD). It automates the process of code integration, testing, building, and deployment to ensure fast and reliable software delivery.
A CI/CD pipeline consists of several key stages:
git add .
git commit -m "Added new feature"
git push origin main
* Goal: Automatically build and test the code to detect issues early.
* Build Stagenpm install
npm run build
mvn clean package
mvn test
npm test
* Goal: Deploy the application to a staging environment for further testing.
* Deployment to Stagingdocker build -t my-app .
docker push my-app:latest
kubectl apply -f deployment.yaml
* Goal: If Continuous Deployment is enabled, code is automatically deployed to production without manual intervention.
* Production Deploymentaws deploy create-deployment \
--application-name MyApp \
--deployment-group-name MyDeploymentGroup \
--s3-location bucket=my-bucket,key=my-app.zip,bundleType=zip
Let's say we have a Node.js application and want to set up a CI/CD pipeline using GitHub Actions.
.github/workflows/ci-cd.yml)name: CI/CD Pipeline
on:
push:
branches:
- main # Run pipeline when code is pushed to the main branch
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build application
run: npm run build
deploy:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Deploy to production
run: echo "Deploying application..."
* Developer pushes code to GitHub.
* GitHub Actions automatically runs CI/CD pipeline.
* Tests run to check for errors.
* If tests pass, the build process starts.
* Application is deployed to a staging environment.
* After approval, the app is deployed to production.
* The website/app is now live for users! ?
* Automates software development (reduces manual effort).
* Detects issues early (ensures code quality).
* Speeds up deployment (fast and reliable releases).
* Enhances collaboration (developers work seamlessly).