This project demonstrates a Java application built and deployed using a Docker pipeline within a Jenkins environment. The final Docker image is hosted on Docker Hub: Java App Pipeline Image.
- Docker: Install and run Docker from here.
- Java 11 or later: Required JDK for the project.
- Maven: Install Maven from here.
- Jenkins: A Jenkins server is required to execute the CI/CD pipeline.
-
Set Up Your Virtual Machines:
- Install Ubuntu on Both VMs:
- Download the Ubuntu ISO and create two VMs in VMware Workstation.
- Install Ubuntu on both VMs.
- Install Required Software:
- On both VMs, update the package list and install the necessary packages:
sudo apt update sudo apt install openjdk-17-jdk git docker.io
- Install Ubuntu on Both VMs:
-
Set Up Jenkins on VM1 (Jenkins Master):
- Add the Jenkins repository and install Jenkins:
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt update sudo apt install jenkins
- Start Jenkins:
- Start Jenkins and enable it to start on boot:
sudo systemctl start jenkins sudo systemctl enable jenkins - Access Jenkins:
- Add the Jenkins repository and install Jenkins:
-
Configure Jenkins Agent on VM2:
-
Create a Jenkins User:
- On VM2, create a user for Jenkins:
sudo useradd -m -s /bin/bash sudo passwd jenkins
-
Install Java and Docker.
-
Set Up SSH Key:
- Generate an SSH key on VM1 and copy it to VM2:
ssh-keygen ssh-copy-id jenkins@<VM2_IP>
-
Configure Jenkins Agent:
-
-
Clone the Repository on VM1:
- Clone the Repository:
- On VM1, clone the repository:
https://github.com/omarMohamedo-o/depi_final_project.git
- Clone the Repository:
-
Modify the Front Page:
-
Jenkins Setup
-
Run the Jenkins Pipeline:
- src/main/java/com/example: Java source code.
- src/main/resources: Configuration files.
- Dockerfile: Instructions for Docker image creation.
- Jenkinsfile: Defines pipeline stages for Jenkins.
- Build: Compile the Java code into a JAR file.
- Test: Optionally run unit or integration tests.
- Docker Build: Build the Docker image using the
Dockerfile. - Docker Push: Push the built image to Docker Hub.
- Deploy: Optionally define deployment steps (currently omitted).
- Application Code: Modify Java files in
srcto change app functionality. - Dockerfile: Adjust base image, dependencies, or installation steps as needed.
- Jenkinsfile: Tailor pipeline stages to fit your specific CI/CD workflow.
-
JAVA_HOME Issue on Jenkins Agent:
- Issue:
UnsupportedClassVersionErrordue to incorrectJAVA_HOMEsetting on the Jenkins agent. - Solution: Correct
JAVA_HOMEin Jenkins agent configuration to point to the JDK 11+ directory.
- Issue:
-
Docker Hub Credentials in Jenkins:
- Issue: Pipeline failed to push the image due to missing credentials.
- Solution: Add Docker Hub credentials to Jenkins and configure the job to use them via the
withCredentialsblock.
You can find the final Docker image on Docker Hub: Java App Pipeline.
Contributions are welcome! Feel free to open issues or submit pull requests.















