This repository contains all the files needed to complete the Jenkins CI/CD Pipeline Lab 6.3.6. The lab demonstrates how to build a complete CI/CD pipeline using Jenkins, Docker, and a sample Flask web application.
This lab teaches you how to:
- Create and containerize a Flask web application
- Set up Jenkins with Docker
- Create Jenkins jobs for building and testing
- Implement a complete CI/CD pipeline
- Automate deployment and testing processes
├── sample_app.py # Main Flask application
├── sample-app.sh # Build and run script
├── templates/
│ └── index.html # HTML template
├── static/
│ └── style.css # CSS styling
├── Jenkinsfile # Jenkins pipeline definition
├── Dockerfile # Docker container definition
├── docker-compose.yml # Docker Compose configuration
├── requirements.txt # Python dependencies
├── test-app.sh # Application testing script
├── setup-jenkins.sh # Jenkins setup script
├── cleanup.sh # Resource cleanup script
└── README.md # This file
- Docker installed and running
- Git installed
- Terminal/Command Line access
First, let's build and run the sample application:
# Make scripts executable
chmod +x *.sh
# Build and run the application
./sample-app.sh
Visit http://localhost:5050
to see the application running.
To set up Jenkins with Docker:
# Run the Jenkins setup script
./setup-jenkins.sh
This will:
- Pull the Jenkins Docker image
- Start Jenkins on port 8080
- Display the admin password
Visit http://localhost:8080
and complete the Jenkins setup with the provided password.
Run the test script to verify the application is working:
./test-app.sh
When you're done with the lab:
./cleanup.sh
- Create a new repository named
sample-app
- Clone this repository and push the files to your GitHub repo
- Configure Git credentials locally
-
Create Build Job (BuildAppJob):
- New Item → Freestyle project
- Source Code Management: Git
- Repository URL: Your GitHub repository
- Build: Execute shell →
bash ./sample-app.sh
-
Create Test Job (TestAppJob):
- New Item → Freestyle project
- Build Triggers: Build after other projects are built →
BuildAppJob
- Build: Execute shell → Use the test script content
-
Create Pipeline Job (SamplePipeline):
- New Item → Pipeline
- Pipeline script: Use the provided Jenkinsfile content
- Trigger the BuildAppJob manually
- Verify both BuildAppJob and TestAppJob complete successfully
- Run the SamplePipeline to see the complete automated workflow
- Flask web application that displays the client's IP address
- Runs on port 5050 to avoid conflicts with Jenkins (port 8080)
- Shell script that builds a Docker container for the Flask app
- Creates temporary directories, copies files, and builds/runs the container
- Defines the complete CI/CD pipeline with stages:
- Preparation: Clean up previous containers
- Build: Run the application build
- Test: Verify the application works
- Deploy: Confirm successful deployment
- HTML template that shows the client's IP address
- Uses Flask templating to display dynamic content
- CSS styling with light steel blue background
- Provides visual formatting for the web page
Useful Docker commands for this lab:
# View running containers
docker ps
# View all containers
docker ps -a
# Stop a container
docker stop samplerunning
# Remove a container
docker rm samplerunning
# View images
docker images
# Remove an image
docker rmi sampleapp
- Ensure port 5050 is free for the Flask app
- Ensure port 8080 is free for Jenkins
- Use
docker ps
to check running containers
- If containers won't start, try the cleanup script
- Check Docker daemon is running
- Verify sufficient disk space
- Wait 30 seconds after starting Jenkins before accessing
- Check the admin password with:
docker exec jenkins_server cat /var/jenkins_home/secrets/initialAdminPassword
By completing this lab, you will understand:
-
Continuous Integration (CI):
- Automated building and testing of applications
- Source code management integration
- Build triggers and dependencies
-
Continuous Deployment (CD):
- Automated deployment processes
- Environment management
- Release automation
-
Jenkins Pipeline:
- Pipeline as Code with Jenkinsfile
- Stage definitions and error handling
- Pipeline visualization and monitoring
-
Docker Integration:
- Containerized applications
- Docker-in-Docker configurations
- Container lifecycle management
After completing this lab, you can explore:
- Multi-branch pipelines
- Integration with GitHub webhooks
- Advanced testing strategies
- Production deployment patterns
- Monitoring and alerting
- Security scanning integration
If you encounter issues:
- Check the troubleshooting section
- Verify all prerequisites are installed
- Ensure Docker is running properly
- Check the console output in Jenkins for detailed error messages