This guide provides step-by-step instructions for setting up a Jenkins CI/CD pipeline for the EasyShop application, including GitHub webhook configuration and shared library integration.
- Prerequisites
- Jenkins Installation
- Jenkins Configuration
- GitHub Webhook Setup
- Pipeline Configuration
- Shared Library Integration
- Ubuntu 22.04 LTS server
- Jenkins installed
- Docker installed
- Git installed
- GitHub account
- Docker Hub account
- Add Jenkins repository key:
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null- Add Jenkins repository:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null- Update package list and install Jenkins:
sudo apt update
sudo apt install jenkins- Start Jenkins service:
sudo systemctl start jenkins
sudo systemctl enable jenkins- Get the initial admin password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword- Access Jenkins:
- Open
http://your-server-ip:8080 - Enter the initial admin password
- Install suggested plugins
- Create admin user
Install these plugins via "Manage Jenkins" > "Manage Plugins" > "Available":
- Docker Pipeline
- Email Extension Plugin
- GitHub Integration Plugin
- Pipeline Utility Steps
- Navigate to "Manage Jenkins" > "Manage Credentials"
- Add Docker Hub credentials:
- Kind: Username with password
- Scope: Global
- ID: docker-hub-credentials
- Username: Your Docker Hub username
- Password: Your Docker Hub password
- Go to "Manage Jenkins" > "Configure System"
- Configure E-mail Notification:
- SMTP server: smtp.gmail.com
- Use SMTP Authentication: Yes
- User Name: Your email
- Password: Your app password
- Use SSL: Yes
- SMTP Port: 465
- Go to GitHub.com > Settings > Developer settings > Personal access tokens
- Generate new token (classic)
- Select scopes:
- repo (all)
- admin:repo_hook
- Save the token
- Add GitHub token to Jenkins credentials:
- Kind: Secret text
- Scope: Global
- ID: github-token
- Description: GitHub Token
- In your GitHub repository:
- Go to Settings > Webhooks
- Add webhook
- Payload URL:
http://your-jenkins-url:8080/github-webhook/ - Content type: application/json
- Select: Just the push event
- Click "New Item"
- Enter name: "easyshop-pipeline"
- Select "Pipeline"
- Configure:
- GitHub project URL
- Build Triggers: GitHub hook trigger for GITScm polling
- Pipeline script from SCM
- Git repository URL
- Branch: */main
- Script Path: Jenkinsfile
Our pipeline uses a shared library from: EasyShop Jenkins Shared Library
- Go to "Manage Jenkins" > "Configure System"
- Under "Global Pipeline Libraries":
- Name: easyshop-shared-lib
- Default version: main
- Modern SCM: GitHub
- Repository URL: https://github.com/iemafzalhassan/EasyShop-jenkins-shared-lib.git
Our pipeline includes these stages:
- Checkout: Cleans workspace and checks out code
- Build Docker Images: Builds application containers
- Push to Docker Hub: Pushes images to registry
- Deploy to Production: Deploys the application
- Email Notification: Sends build status
Important log locations:
- Jenkins logs:
/var/log/jenkins/jenkins.log - Docker logs:
docker logs container-name - Build logs: Available in Jenkins job console output