This project implements an automated CI/CD pipeline for a multi-branch GitHub repository using Jenkins and Docker. It establishes separate automated workflows for development (dev
) and production (main
) branches, enabling continuous integration and deployment with proper separation of concerns between environments.
The pipeline automatically builds, tests, and creates Docker images that are published to different registries based on the branch. Development builds are published to GitHub Packages while production builds can be optionally deployed to Docker Hub.
- Branch-Specific Workflows: Separate CI/CD pipelines for development (
dev
) and production (main
) branches - Automated Testing: Continuous integration with automated tests for every code change
- Docker Integration: Automatic Docker image building with environment-specific tagging
- Multi-Registry Support: Publishes to GitHub Packages for development and Docker Hub for production
- Parameterized Production Deploys: Optional deployment with customizable image tagging for production
- Code Quality Gates: Branch protection rules ensure quality checks pass before merging to production
- Automated Triggering: Jenkins polling configuration detects code changes automatically
- Version Control: GitHub with multi-branch workflow
- CI/CD: Jenkins Multibranch Pipeline
- Containerization: Docker with multi-registry support
- Image Registries: GitHub Packages and Docker Hub
- Automation: Jenkinsfile declarative pipelines
- Monitoring: Slack integration (configured but pending notifications)
- Security: Branch protection rules
- Developers commit code to the
dev
branch - Jenkins polls for changes and automatically detects new commits
- The development pipeline is triggered, which:
- Clones the repository
- Builds the project
- Runs unit and integration tests
- Creates a Docker image tagged as
dev
- Publishes the image to GitHub Packages
- Development code is submitted to the
main
branch via Pull Request - Branch protection rules enforce review requirements
- Once merged, Jenkins detects changes through polling
- The production pipeline executes with parameters:
- Verifies code changes
- Builds and tests the application
- Creates a Docker image with customizable tag
- Optionally deploys the image to Docker Hub when enabled
- Jenkins server with:
- Multibranch Pipeline plugin
- Docker Pipeline plugin
- Git integration
- Docker installed on Jenkins server
- GitHub account with repository access
- Docker Hub account (for production deployments)
- Create a new Multibranch Pipeline job in Jenkins
- Configure source code management:
- Add GitHub repository URL
- Configure credentials for repository access
- Set up branch sources:
- Configure to discover branches and PRs
- Add
main
anddev
as branch specifiers
- Set up build configuration:
- Mode: by Jenkinsfile
- Script path:
Jenkinsfile
(for each branch)
- Configure polling trigger:
- Set appropriate interval (e.g.,
H/5 * * * *
for every 5 minutes)
- Set appropriate interval (e.g.,
- Save the configuration
- Create repository with two branches:
main
anddev
- Add branch protection rules for
main
:- Require pull request reviews before merging
- Require status checks to pass before merging
- Add Jenkinsfiles to both branches:
Jenkinsfile
in themain
branchJenkinsfile.dev
in thedev
branch
- Replace polling with GitHub webhooks for immediate pipeline triggering
- Fix Slack notification issues to enable real-time build status alerts
- Add vulnerability scanning for Docker images
- Implement automated rollback mechanisms for failed deployments
graph TD
A[Code Change] --> B{Branch?}
B -->|dev| C[Dev Pipeline]
B -->|main| D[Main Pipeline]
C --> C1[Build]
C1 --> C2[Test]
C2 --> C3[Create Docker Image]
C3 --> C4[Push to GitHub Packages]
D --> D1[Build]
D1 --> D2[Test]
D2 --> D3[Create Docker Image]
D3 --> D4{Deploy?}
D4 -->|Yes| D5[Push to Docker Hub]
D4 -->|No| D6[End Pipeline]
- Credentials are managed securely in Jenkins credentials store
- Branch protection rules enforce code review before merging to
main
- Docker images use minimal base images to reduce attack surface