What is the Purpose of a CI/CD Pipeline?
CI/CD Pipeline – Key Purposes:
When to Use CI/CD Pipelines?
Why Use a Pipeline?
How Is a Pipeline Used? (Basic Flow)
How Is a Pipeline Used using github
Step-by-Step Setup: Jenkins Pipeline with GitHub on Ubuntu
Application of CI/CD pipeline in different field
write a code of CI/CD pipeline in different field
Explain the different format of CI/CD pipeline
What is the Purpose of a CI/CD Pipeline?
CI/CD stands for Continuous Integration and Continuous Deployment/Delivery. The CI/CD pipeline is a process that automates software development stages like:
Continuous Integration (CI): Developers frequently push small code changes to a shared repository. These changes are automatically tested and built to catch errors early.
Continuous Delivery (CD): Code changes are automatically prepared for release, making the software always deployment-ready.
Continuous Deployment (the other CD): Every code change that passes all tests is automatically deployed to production without manual approval.
Building code
Running tests
Deploying applications
The goal is to deliver software faster, more reliably, and with fewer bugs.
CI/CD Pipeline – Key Purposes:
Automation: Reduces manual work (build, test, deploy).
🚨 Early Bug Detection: Catches bugs before production.
🔁 Faster Feedback: Developers get quick feedback after code changes.
📦 Consistent Deployments: Ensures every deployment is the same.
📈 Improves Productivity: Teams focus on coding, not deployments.
When to Use CI/CD Pipelines?
When you're working in a team that regularly updates code.
When you have multiple environments like dev, staging, and production.
When your application is updated frequently.
When you want to release new features or fixes quickly and safely.
How Is a Pipeline Used? (Basic Flow)
Developer pushes code to a repository (e.g., GitHub).
CI/CD system (e.g., GitLab CI, GitHub Actions, Jenkins) detects changes.
Pipeline is triggered:
🏗 Build: Compile the code.
✅ Test: Run unit/integration tests.
🔍 Analyze: Check code quality.
📦 Package: Create a deployable artifact.
🚀 Deploy: Push to dev/staging/production.
💼 Use Case Examples
Web Application Development
Automatically test and deploy updates to the website every time code is pushed.Mobile App Development
Build and test Android/iOS apps on every commit before publishing to the Play Store.Microservices Architecture
Each microservice has its own pipeline for independent testing and deployment.Infrastructure as Code (IaC)
Use CI/CD to apply infrastructure changes via tools like Terraform or Ansible.
How Is a Pipeline Used using github
Prerequisites:
A GitHub account.
A GitHub repository with your project code (Node.js, Python, Laravel, React, etc.).
Basic knowledge of Git.
🔧 Step 1: Create or Open Your GitHub Repository
If you don't already have a repo:
# Create a new local project
mkdir my-project && cd my-project
git init
echo "# My Project" > README.md
git add .
git commit -m "Initial commit"
# Push it to GitHub
git remote add origin https://github.com/your-username/my-project.git
git push -u origin master
📝 Step 2: Add a GitHub Actions Workflow File
Go to your repo on GitHub.
Navigate to the folder: .github/workflows/
If it doesn’t exist, create it.
Create a new file: ci.yml (or any name ending in .yml)
🧪 Step 3: Sample CI Workflow (Example: Node.js Project)
name: CI Pipeline
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
🧬 Step 4: Commit and Push Workflow File
git add .github/workflows/ci.yml
git commit -m "Add GitHub Actions CI pipeline"
git push origin main
✅ Step 5: See It in Action
Go to your GitHub repo.
Click on the "Actions" tab.
You'll see your pipeline running under the name "CI Pipeline".
🔄 Optional: Add Deployment Step
For example, if deploying to GitHub Pages, Netlify, or an FTP server, add another step in ci.yml.
Example: Deploy to GitHub Pages (for static sites)
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
Step-by-Step Setup: Jenkins Pipeline with GitHub on Ubuntu
Step 1: Install Jenkins on Ubuntu
Run these commands:
sudo apt update
sudo apt install openjdk-17-jdk -y # or Java 11
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y
sudo systemctl start jenkins
sudo systemctl enable jenkins
Access Jenkins at: http://localhost:8080
🔐 Step 2: Unlock Jenkins
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Use the output to log in. Then install Suggested Plugins.
🔌 Step 3: Install Required Jenkins Plugins
Go to:
Dashboard → Manage Jenkins → Manage Plugins → Available tab, and install:
Git plugin
GitHub plugin
Pipeline
GitHub Integration
Blue Ocean (optional: for better UI)
🔐 Step 4: Add GitHub Credentials in Jenkins
Go to:
Manage Jenkins → Credentials → Global → Add Credentials
Kind: Username with password or Personal Access Token (GitHub PAT)
ID: github-token
Description: GitHub Access
📁 Step 5: Create a New Pipeline Job
Go to Dashboard → New Item
Enter a name (e.g., my-github-pipeline)
Choose Pipeline, click OK
🧬 Step 6: Configure the Pipeline
GitHub Project: Tick ✅ and enter your repo URL (e.g., https://github.com/username/repo)
Pipeline Definition: Choose Pipeline script from SCM
SCM: Git
Repository URL: https://github.com/username/repo.git
Credentials: Choose your saved GitHub token
Branch: */main or */master
Script Path: Jenkinsfile (default if your file is at repo root)
📝 Step 7: Create a Jenkinsfile in GitHub Repo
Example: For a Node.js app
pipeline {
agent any
stages {
stage('Clone Code') {
steps {
git url: 'https://github.com/username/repo.git', branch: 'main'
}
}
stage('Install Dependencies') {
steps {
sh 'npm install'
}
}
stage('Run Tests') {
steps {
sh 'npm test'
}
}
stage('Build') {
steps {
sh 'npm run build'
}
}
}
}
Customize it for Maven, Laravel, Python, etc.
▶️ Step 8: Build the Pipeline
Back in Jenkins:
Click Build Now
Watch progress in Console Output
🔁 Step 9: Trigger Builds on GitHub Push (Optional)
In GitHub repo:
Go to Settings → Webhooks
Add a webhook:
Payload URL: http://your-server-ip:8080/github-webhook/
Content type: application/json
Trigger: Push events
In Jenkins:
Go to your job → Configure
Tick ✅ GitHub hook trigger for GITScm polling
Application of CI/CD pipeline in different field
Continuous Integration (CI) and Continuous Delivery (CD) are vital components in modern software development that help automate the process of building, testing, and deploying software. CI/CD pipelines can be implemented in various fields and technologies. Below is a list of the different fields where CI/CD pipelines are commonly used:
-
Software Development
Automated Builds
: CI/CD pipelines automatically compile and build the software whenever changes are made to the codebase.
Automated Testing
: Unit tests, integration tests, and UI tests are run automatically as part of the CI pipeline to ensure code quality.
Deployment
: CD pipelines automatically deploy applications to staging or production environments after passing tests.
-
Web Development
Frontend Applications
: React, Angular, Vue.js, etc. use CI/CD to automate deployment to web servers, update content, and ensure continuous integration of code.
Backend APIs
: Node.js, Django, Flask, Ruby on Rails, etc., use CI/CD pipelines for integration and delivery of APIs.
Static Websites
: CI/CD pipelines can deploy static websites using frameworks like Hugo, Jekyll, and Gatsby to platforms like Netlify or GitHub Pages.
-
Mobile App Development
iOS (Swift, Objective-C)
: CI/CD is used to automate the process of building, testing, and deploying iOS apps via Xcode and App Store Connect.
Android (Kotlin, Java)
: CI/CD pipelines automate the building, testing, and releasing of Android apps to Google Play Store.
Cross-Platform Apps (Flutter, React Native)
: Automates the process of testing and deployment for iOS and Android versions.
-
Cloud Computing
Cloud Platforms
: CI/CD pipelines are used for automating the deployment and scaling of applications to cloud platforms like AWS, Azure, Google Cloud, and DigitalOcean.
Infrastructure as Code (IaC)
: Automating the provisioning of cloud infrastructure with tools like Terraform, Ansible, and CloudFormation.
Serverless
: CI/CD pipelines manage serverless deployments using platforms like AWS Lambda or Google Cloud Functions.
-
DevOps
Automation of Testing & Deployment
: CI/CD pipelines help DevOps teams automate testing, building, and deploying to development, staging, or production environments.
Monitoring & Alerting
: CI/CD integrates with monitoring tools to automate the response to incidents.
Containerization & Orchestration
: CI/CD pipelines deploy applications in containers (Docker, Kubernetes) and manage scaling.
-
Game Development
Automated Builds and Deployment
: Game studios use CI/CD pipelines to automate building, testing, and deploying game versions for different platforms.
Automated Testing
: CI pipelines automatically run performance and unit tests for games, such as testing AI behavior or user input.
Game Servers
: CI/CD is used to deploy and update multiplayer game servers with new features or patches.
-
Data Science & Machine Learning
Model Training and Deployment
: ML models are automatically trained and deployed to production environments in CI/CD pipelines.
Data Processing Pipelines
: Automating the extraction, transformation, and loading (ETL) of data into the system.
Model Testing & Evaluation
: CI pipelines can include automated tests for model performance, accuracy, and regression.
-
Embedded Systems
Firmware Deployment
: CI/CD pipelines manage the testing and deployment of embedded software and firmware to devices in the field.
Continuous Testing
: Automates testing on different hardware platforms to ensure the firmware works properly across multiple devices.
OTA (Over-the-Air) Updates: Automates firmware updates for devices deployed in the field via CI/CD.
-
Microservices & API Development
Microservice Deployments
: CI/CD pipelines are crucial for managing microservice architectures, where each service is built, tested, and deployed independently.
API Integration
: Automatically testing and deploying APIs with full integration and unit tests to ensure all services work together.
-
Database Development
Database Migrations
: CI/CD pipelines automate the process of database schema changes, migrations, and rollbacks.
Automated Database Testing
: CI/CD pipelines can ensure that SQL queries and stored procedures work correctly with every new change.
Version Control for Databases
: Automatically tracking database changes and ensuring synchronization across environments.
-
Security (DevSecOps)
Automated Security Testing
: Integrating security scans and tests (SAST, DAST) into the CI/CD pipeline to identify vulnerabilities early in the development cycle.
Automated Compliance Checks
: Ensuring regulatory compliance by automatically testing and enforcing rules on code deployment.
-
Infrastructure & Networking
Automated Provisioning
: CI/CD pipelines integrate infrastructure provisioning tools like Terraform or Ansible to automate the setup of network infrastructure and servers.
Network Configuration Management
: Automating configurations of routers, switches, and firewalls.
-
API and Backend Testing (for SaaS)
Continuous Integration of Backend APIs
: API developers use CI/CD pipelines to integrate and deploy backend APIs to cloud platforms for SaaS products.
API Load Testing
: Automating API performance and load tests to ensure scalability of SaaS products.
-
Continuous Delivery of Web Services & SaaS Products
Deploying SaaS Platforms
: CI/CD pipelines automate deployment of software as a service, ensuring minimal downtime and continuous improvements.
A/B Testing
: Use CI/CD to automate the deployment of different versions of a service for user feedback and experimentation.
write a code of CI/CD pipeline in different field
Software Development (Automated Builds and Testing
CI/CD Tool: Jenkins, GitHub Actions, GitLab CI, Travis CI, CircleCI
Example with GitHub Actions:
name: Build and Test
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build app
run: npm run build
- name: Deploy (optional)
run: npm run deploy
GitHub Actions (Node.js Automated Build and Testing)
This GitHub Actions workflow automatically builds and tests a Node.js application whenever changes are pushed to the main branch.
name: Node.js CI
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build app
run: npm run build
- name: Deploy (optional)
run: npm run deploy
-
Jenkins (Java Maven Build and Test)
This Jenkins pipeline script automates the building, testing, and deploying of a Java project using Maven.
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
sh 'mvn clean install'
}
}
}
stage('Test') {
steps {
script {
sh 'mvn test'
}
}
}
stage('Deploy') {
steps {
script {
sh 'mvn deploy'
}
}
}
}
}
-
GitLab CI (Python Automated Testing with Pytest)
This GitLab CI configuration runs tests using Pytest in a Python application.
stages:
- build
- test
build:
stage: build
script:
- python -m venv venv
- pip install -r requirements.txt
test:
stage: test
script:
- pytest tests/
artifacts:
paths:
- reports/
-
Travis CI (React App with Jest Testing)
This Travis CI configuration automates testing for a React application using Jest.
language: node_js
node_js:
- "14"
script:
- npm install
- npm test -- --coverage
after_success:
- npm run build
- npm run deploy
-
CircleCI (JavaScript & Cypress for E2E Testing)
This CircleCI configuration sets up Cypress for end-to-end testing in a JavaScript-based app.
version: 2.1
jobs:
build:
docker:
- image: circleci/python:3.8
steps:
- checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Run Cypress tests
command: npx cypress run
deploy:
docker:
- image: circleci/python:3.8
steps:
- checkout
- run:
name: Build the app
command: npm run build
- run:
name: Deploy the app
command: npm run deploy
workflows:
version: 2
build_and_deploy:
jobs:
- build
- deploy:
requires:
- build
- Web Development (Frontend) CI/CD Tool: GitHub Actions, CircleCI, Travis CI
Example with GitHub Actions (React App):
name: Build React App
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test -- --coverage
- name: Build app
run: npm run build
- name: Deploy to Netlify (or any platform)
run: netlify deploy --prod
- Mobile App Development (React Native or Flutter) CI/CD Tool: Bitrise, GitHub Actions, CircleCI, Jenkins
Example with GitHub Actions (React Native):
name: Build and Test React Native App
on:
push:
branches:
- main
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Install CocoaPods dependencies
run: cd ios && pod install && cd ..
- name: Run tests
run: npm test
- name: Build app (for iOS)
run: npx react-native run-ios --configuration Release
- name: Build app (for Android)
run: npx react-native run-android --variant=release
GitHub Actions (React Native: Build and Test iOS and Android)
This GitHub Actions workflow automates the build and test process for a React Native app for both iOS and Android.
name: Build and Test React Native App
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
ios:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Install CocoaPods dependencies
run: cd ios && pod install && cd ..
- name: Run iOS tests
run: npx react-native run-ios --configuration Release
android:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run Android tests
run: npx react-native run-android --variant=release
-
Bitrise (Flutter: Build and Test Flutter App
) This Bitrise configuration automates the Flutter app testing and building process, ensuring that the app runs tests for both Android and iOS.
app:
name: FlutterApp
platform: flutter
workflows:
primary:
steps:
- activate-ssh-key@4:
run_if: '{{ .IsPullRequest }}'
- flutter-installer@0:
inputs:
flutter_version: "stable"
- flutter-test@0:
inputs:
flutter_version: "stable"
- flutter-build@0:
inputs:
platform: "ios"
- flutter-build@0:
inputs:
platform: "android"
-
CircleCI (React Native: E2E Testing with Detox)
This CircleCI configuration automates the end-to-end testing of a React Native app using Detox for both iOS and Android.
version: 2.1
jobs:
build:
docker:
- image: circleci/node:14
steps:
- checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Install CocoaPods
command: cd ios && pod install && cd ..
test:
docker:
- image: circleci/node:14
steps:
- checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Run Detox tests for iOS
command: npm run test:e2e:ios
- run:
name: Run Detox tests for Android
command: npm run test:e2e:android
workflows:
version: 2
build_and_test:
jobs:
- build
- test:
requires:
- build
-
Jenkins (Flutter: Build iOS and Android App)
This Jenkins pipeline builds both iOS and Android versions of a Flutter app using specific build commands.
pipeline {
agent any
stages {
stage('Install Flutter Dependencies') {
steps {
script {
sh 'flutter pub get'
}
}
}
stage('Build Android App') {
steps {
script {
sh 'flutter build apk --release'
}
}
}
stage('Build iOS App') {
steps {
script {
sh 'flutter build ios --release --no-codesign'
}
}
}
stage('Run Tests') {
steps {
script {
sh 'flutter test'
}
}
}
}
}
-
GitLab CI (React Native: Build, Test, and Deploy)
This GitLab CI configuration automates the build, test, and deployment process of a React Native app to Google Play Store and App Store.
stages:
- build
- test
- deploy
build:
stage: build
script:
- npm install
- npx react-native run-android --variant=release
- npx react-native run-ios --configuration Release
test:
stage: test
script:
- npm run test
deploy_android:
stage: deploy
script:
- npm run deploy:android
only:
- master
deploy_ios:
stage: deploy
script:
- npm run deploy:ios
only:
- master
- Cloud Computing (AWS/Azure/Google Cloud) CI/CD Tool: AWS CodePipeline, Azure DevOps, Google Cloud Build
Example for AWS CodePipeline (using AWS CLI):
aws codepipeline create-pipeline --pipeline-name MyAppPipeline --role-arn arn:aws:iam::123456789012:role/MyAppRole --artifact-store location=MyS3Bucket
- DevOps (Deployment Automation with Docker) CI/CD Tool: Jenkins, GitLab CI, CircleCI, AWS CodePipeline
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
docker.build('myapp')
}
}
}
stage('Test') {
steps {
script {
docker.run('myapp', 'npm test')
}
}
}
stage('Deploy') {
steps {
script {
docker.withRegistry('', 'dockerhub-credentials') {
docker.image('myapp').push()
}
}
}
}
}
}
GitHub Actions (Deploy Infrastructure with Terraform)
This GitHub Actions workflow automates the deployment of infrastructure using Terraform. It provisions resources on a cloud platform like AWS.
name: Deploy Infrastructure with Terraform
on:
push:
branches:
- main
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: '0.14.0'
- name: Terraform Init
run: terraform init
- name: Terraform Plan
run: terraform plan
- name: Terraform Apply
run: terraform apply -auto-approve
- name: Terraform Output
run: terraform output
-
Jenkins (Deploy to Kubernetes using Helm)
This Jenkins pipeline deploys an application to Kubernetes using Helm and automates the entire deployment process.
pipeline {
agent any
stages {
stage('Clone Repository') {
steps {
git 'https://github.com/yourrepo.git'
}
}
stage('Install Helm') {
steps {
sh 'curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash'
}
}
stage('Deploy to Kubernetes') {
steps {
sh 'helm upgrade --install myapp ./helm/myapp --namespace production'
}
}
stage('Verify Deployment') {
steps {
sh 'kubectl get pods --namespace production'
}
}
}
}
-
GitLab CI (AWS EC2 Deployment with AWS CLI)
This GitLab CI configuration automates the deployment of an app to an AWS EC2 instance using the AWS CLI.
stages:
- deploy
deploy:
stage: deploy
script:
- echo "Deploying to AWS EC2"
- aws ec2 describe-instances --region us-west-2
- aws s3 cp ./build/ s3://my-app-bucket --recursive
- ssh -i /path/to/key.pem ec2-user@my-ec2-instance "cd /var/www/my-app && git pull origin main && npm install && npm start"
only:
- master
-
CircleCI (Deploy Infrastructure to Google Cloud using Terraform
) This CircleCI pipeline automates the deployment of infrastructure to Google Cloud using Terraform.
version: 2.1
jobs:
terraform:
docker:
- image: hashicorp/terraform:light
steps:
- checkout
- run:
name: Terraform Initialize
command: terraform init
- run:
name: Terraform Plan
command: terraform plan
- run:
name: Terraform Apply
command: terraform apply -auto-approve
workflows:
version: 2
deploy_infrastructure:
jobs:
- terraform
-
AWS CodePipeline (Continuous Deployment to AWS Lambda)
This AWS CodePipeline automates the deployment of a Lambda function to AWS. It ensures your Lambda function is deployed each time new code is pushed to the repository.
{
"version": "1",
"phases": {
"build": {
"commands": [
"echo Building Lambda Function...",
"npm install",
"zip -r lambda.zip ."
]
},
"post_build": {
"commands": [
"aws lambda update-function-code --function-name myLambdaFunction --zip-file fileb://lambda.zip"
]
}
},
"artifacts": {
"files": [
"lambda.zip"
]
}
}
- Game Development (CI/CD for Unity) CI/CD Tool: Unity Cloud Build, Jenkins, GitHub Actions
Example with Unity Cloud Build:
Connect your Unity Project to Unity Cloud Build.
Set up the build settings and triggers for different platforms (iOS, Android, WebGL, etc.).
- Data Science and Machine Learning CI/CD Tool: Jenkins, GitLab CI, CircleCI
Example with GitLab CI (ML model deployment):
stages:
- build
- test
- deploy
build:
script:
- python -m venv venv
- pip install -r requirements.txt
test:
script:
- pytest tests/
deploy:
script:
- python deploy_model.py
- Embedded Systems CI/CD Tool: Jenkins, GitHub Actions, GitLab CI
Example with GitHub Actions (Firmware for Embedded Devices):
name: Build and Deploy Embedded Firmware
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Arduino
uses: actions/setup-arduino@v2
with:
version: 1.8.15
- name: Build Firmware
run: arduino-cli compile --fqbn arduino:avr:uno /path/to/your/project
- name: Deploy Firmware (e.g., using avrdude)
run: avrdude -c arduino -p m328p -P /dev/ttyACM0 -U flash:w:/path/to/your/firmware.hex
- Microservices/API Development CI/CD Tool: Jenkins, GitHub Actions, GitLab CI
Example with GitHub Actions (API Deployment):
name: Build and Deploy API
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
- name: Build Docker Image
run: docker build -t myapi .
- name: Deploy to AWS
run: |
aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment
- Database Development CI/CD Tool: Jenkins, GitLab CI, CircleCI
Example with GitHub Actions (Database Migration):
name: DB Migration
on:
push:
branches:
- main
jobs:
migrate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up PostgreSQL
uses: docker://postgres:latest
- name: Run Migration
run: |
psql -h localhost -U postgres -d mydb -f migrate.sql
- Security (DevSecOps) CI/CD Tool: GitLab CI, Jenkins, CircleCI
Example for Static Application Security Testing (SAST) with GitLab CI:
stages:
- build
- test
- deploy
security:
stage: test
script:
- docker run --rm -v $(pwd):/project snyk/snyk-cli test
- Infrastructure as Code (IaC) CI/CD Tool: Jenkins, GitLab CI, CircleCI
Example with GitLab CI (Terraform Deployment):
stages:
- init
- plan
- apply
init:
script:
- terraform init
plan:
script:
- terraform plan -out=tfplan
apply:
script:
- terraform apply tfplan
- API and Backend Testing (for SaaS) CI/CD Tool: Jenkins, GitLab CI, CircleCI
Example with GitHub Actions (API Testing with Postman):
name: API Testing
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Newman
run: npm install -g newman
- name: Run Postman Collection
run: newman run collection.json -e environment.json
Explain the different format of CI/CD pipeline
Simple Linear CI/CD Pipeline (Example: GitHub Actions)
This is the most basic form of CI/CD pipeline where stages are executed sequentially, one after another.
Stages:
Stage 1: Build
Code compilation
Dependency installation
Stage 2: Test
Unit tests
Integration tests
Stage 3: Deploy
Deploying to staging environment
Example (GitHub Actions)
:
name: Node.js CI
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Deploy
run: npm run deploy
Purpose
:
Simple Linear Pipelines are ideal for small projects or applications where the process is straightforward and doesn't require advanced logic or parallelism.
How to Identify
:
Sequential Execution: Stages and steps are executed one by one.
No Parallel Jobs: Each stage depends on the completion of the previous one.
No Special Branch Logic: No checks for branch-specific behavior, and the same pipeline runs for all branches.
It’s a straightforward flow from build to test and then deploy.
- Branch-based CI/CD Pipeline (Example: GitLab CI/CD) Branch-based pipelines are triggered based on the branch you're working on (e.g., main, develop). You can define separate deployment pipelines for staging and production with manual approval stages.
Stages:
Stage 1: Build
Code compilation
Dependency installation
Stage 2: Test
Unit tests
Integration tests
Stage 3: Deploy
Deploying to staging environment
Stage 4: Manual Approval
Manual approval required before deploying to production
Example (GitLab CI/CD):
stages:
- build
- test
- deploy
- approve
build:
stage: build
script:
- npm install
test:
stage: test
script:
- npm test
deploy:
stage: deploy
script:
- npm run deploy:staging
only:
- develop
manual_approval:
stage: approve
when: manual
script:
- echo "Waiting for manual approval"
only:
- main
Purpose
:
Branch-based pipelines provide more flexibility by allowing different pipelines for various branches. For example, changes pushed to develop could go to staging, while main requires manual approval before being deployed to production.
How to Identify
:
Branch-Specific Logic: You’ll see conditions that check for specific branches (e.g., only: master or if branch == main).
Manual Approval: You may find stages that require manual approval for deployment to production, often after successful tests.
This format integrates with Git workflows, helping teams maintain control over the deployment process, especially for critical environments.
- Multi-Branch CI/CD Pipeline (Example: Jenkins Pipeline) A multi-branch pipeline allows each branch in a version control system to have its own pipeline. This format is beneficial for complex workflows with different environments.
Stages:
Stage 1: Build
Code compilation
Dependency installation
Stage 2: Test
Unit tests
Integration tests
Stage 3: Deploy
Deploying to staging environment
Stage 4: Promotion
Promotion to production after successful tests
Example (Jenkins Pipeline):
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Deploy') {
steps {
sh 'npm run deploy:staging'
}
}
stage('Promotion') {
when {
branch 'main'
}
steps {
sh 'npm run deploy:production'
}
}
}
}
Purpose
:
Multi-branch pipelines automatically create a pipeline for each branch. For example, when a new branch is created, Jenkins triggers a pipeline based on the branch's configuration.
How to Identify
:
Dynamic Pipeline Generation: A pipeline is created for each branch.
Promotion Logic: After successful tests, the code from the development branch is "promoted" to staging/production.
This is useful for feature branches, staging, and production workflows, and it allows you to promote builds to production only after successful tests.
- Parallel CI/CD Pipeline (Example: CircleCI) A parallel pipeline allows multiple stages to run simultaneously, speeding up the process and reducing overall build time.
Stages:
Stage 1: Build & Test
Parallel execution of build and test stages
Stage 2: Deploy
Deploying to staging environment
Stage 3: Approval
Manual approval before deploying to production
version: 2.1
jobs:
build:
docker:
- image: circleci/node:14
steps:
- checkout
- run:
name: Install dependencies
command: npm install
test:
docker:
- image: circleci/node:14
steps:
- checkout
- run:
name: Run tests
command: npm test
deploy:
docker:
- image: circleci/node:14
steps:
- checkout
- run:
name: Deploy to staging
command: npm run deploy:staging
approval:
type: approval
requires:
- deploy
workflows:
version: 2
build_and_test:
jobs:
- build
- test
- deploy:
requires:
- build
- test
- approval:
requires:
- deploy
Purpose
:
Parallel pipelines speed up the process by running build and test jobs in parallel instead of sequentially. This is useful when you have independent tasks that can be executed simultaneously.
After the parallel stages complete, manual approval can be added for deploying to production.
How to Identify
:
Parallel Jobs: Multiple jobs or steps are executed concurrently, which can be explicitly defined in the configuration.
Job Dependencies: The jobs or stages that can run independently are defined to run simultaneously.
- Fan-in/Fan-out CI/CD Pipeline (Example: Travis CI) Fan-in/Fan-out pipelines allow for parallel execution of tasks and then combine the results. This can be used to run multiple tests in parallel and then merge the results before moving on to the next stage.
Stages:
Stage 1: Build & Test
Fan-out to multiple parallel test stages
Stage 2: Merge & Deploy
Fan-in after successful tests and deploying to staging environment
Stage 3: Promotion
Promotion to production after manual approval
Example (Travis CI):
jobs:
include:
- stage: Build
script: npm install
- stage: Test
script: npm test
deploy:
stage: deploy
script: npm run deploy
on:
branch: main
promotion:
stage: promotion
script: npm run promote
on:
branch: main
condition: manual
Purpose:
Fan-in/Fan-out pipelines are beneficial when you need to run different sets of tests or tasks concurrently (fan-out) and then bring all the results back together (fan-in) before continuing the pipeline. This is useful for applications with complex test suites or when there are multiple dependencies between tasks.
How to Identify
:
Fan-out: Multiple tasks are running in parallel, such as running different tests for different parts of the application.
Fan-in: After the parallel jobs, the results are merged to continue with further tasks (e.g., deployment or promotion).
Top comments (0)