This project demonstrates a basic CI/CD pipeline using Jenkins and Docker. The application is a simple Flask-based portfolio website that is automatically built and deployed through Jenkins whenever code changes are pushed to GitHub.
jenkins-basic-ci/
├── portfolio-site/
│ ├── app.py # Flask application
│ ├── requirements.txt # Python dependencies
│ ├── Dockerfile # Docker configuration
│ ├── templates/
│ │ └── index.html # Portfolio website HTML
│ └── static/
│ └── style.css # Styling
├── Jenkinsfile # Jenkins pipeline configuration
├── README.md # This file
└── .gitignore # Git ignore rules
- Source Code Management: The portfolio-site code is stored in a GitHub repository
- Continuous Integration: Jenkins polls the GitHub repository for changes
- Automated Build: When changes are detected, Jenkins automatically:
- Clones the latest code
- Builds a Docker image for the portfolio-site
- Runs the Docker container on port 5002
- Continuous Deployment: The application is immediately available at
http://localhost:5002
- Docker: Installed and running on your machine
- Docker Socket: Available at
/var/run/docker.sock(for Jenkins to access Docker) - Git: For version control and cloning the repository
- GitHub Account: To host the repository
Open PowerShell as Administrator and run:
docker run -d -p 8080:8080 -p 50000:50000 --name jenkins `
-v jenkins_home:/var/jenkins_home `
-v /var/run/docker.sock:/var/run/docker.sock `
jenkins/jenkins:ltsWait 2-3 minutes for Jenkins to start, then retrieve the initial admin password:
docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPasswordCopy the password and go to http://localhost:8080 to unlock Jenkins.
- Install suggested plugins
- Create a new admin user (remember username and password)
- Click New Item
- Name it:
portfolio-site-build - Select Freestyle project → Click OK
- Under Source Code Management, select Git
- Enter your GitHub repository URL:
https://github.com/MRG-Hazmatz/jenkins-basic-ci.git - Set Branch to:
*/main - Leave credentials blank (for public repos)
- Click Save
- Go back to job configuration
- Under Build Triggers, check Poll SCM
- Enter schedule:
H/5 * * * *(polls every 5 minutes) - Click Save
- Under Build, click Add build step → Select Execute shell
- Paste these commands:
cd portfolio-site
docker build -t portfolio-site .
docker run -d -p 5002:5000 portfolio-site- Click Save
- Click Build Now
- Check the build logs for success
- Visit
http://localhost:5002to see your portfolio site
Developer pushes code to GitHub
↓
Jenkins detects changes (via Poll SCM)
↓
Jenkins clones the repository
↓
Dockerfile builds the Docker image
↓
Docker container runs on port 5002
↓
Application is live at http://localhost:5002
FROM python:3.11-slim # Base image: Python 3.11
WORKDIR /app # Set working directory
COPY requirements.txt . # Copy dependency file
RUN pip install -r requirements.txt # Install dependencies
COPY app.py . # Copy Flask app
EXPOSE 5000 # Expose port 5000
CMD ["python", "app.py"] # Run the app on startupThe app.py file is a simple Flask application that:
- Serves the portfolio website
- Listens on port 5000 inside the container
- Maps to port 5002 on the host machine
- Manual trigger: Click "Build Now" in Jenkins
- Automated trigger: Jenkins automatically detects code changes every 5 minutes (Poll SCM)
- Build execution: Docker builds and runs the container
- Access: Visit
http://localhost:5002to access the live application
- Ensure Docker is running
- Check if port 8080 is available
- Ensure Jenkins container has Docker socket mounted (
-v /var/run/docker.sock:/var/run/docker.sock) - Restart Jenkins container
- Check if container is running:
docker ps - Check logs:
docker logs portfolio-site(use actual container ID)
- Jenkins Dashboard Title: Jenkins Dashboard Explanation: Main Jenkins homepage showing the list of jobs and overall build status.
- Jenkins Triggers Title: Jenkins Build Triggers Explanation: The job configuration screen with "Poll SCM" selected to enable auto-builds on code changes.
- Jenkins Build Steps Title: Jenkins Build Steps Explanation: Build configuration showing shell commands for building and running the Dockerized Flask app.
- Jenkins SCM Title: Jenkins SCM (Source Code Management) Explanation: Configuration showing GitHub repository URL and branch setup for code checkout.
- Portfolio demo site Running Title: Portfolio Site Running Explanation: The Flask portfolio application successfully running and accessible at localhost:5002.
- Add more features to the Flask app
- Configure GitHub webhooks for instant builds (instead of polling)
- Add post-build actions (notifications, artifact archiving)
- Set up multiple environments (dev, staging, production)
Created as part of DevOps/CI-CD training for Jenkins and Docker integration.