diff --git a/Jenkins/CD-Pipeline b/Jenkins/CD-Pipeline new file mode 100644 index 00000000..f24c5e67 --- /dev/null +++ b/Jenkins/CD-Pipeline @@ -0,0 +1,15 @@ +pipeline { + agent any + + stages { + stage('Docker Deploy To Container') { + steps { + script{ + withDockerRegistry(credentialsId: '', toolName: 'docker') { + sh "docker run -d --name shopping -p 8070:8070 /shopping:latest" + } + } + } + } + } +} diff --git a/Jenkins/CI-Pipeline b/Jenkins/CI-Pipeline new file mode 100644 index 00000000..c2303058 --- /dev/null +++ b/Jenkins/CI-Pipeline @@ -0,0 +1,62 @@ +pipeline { + agent any + + tools{ + jdk 'jdk11' + maven 'maven3' + } + + environment{ + SCANNER_HOME= tool 'sonar-scanner' + } + + stages { + stage('Git CheckOut') { + steps { + git branch: 'main', changelog: false, poll: false, url: 'https://github.com/' + } + } + stage('Compile using Maven') { + steps { + sh "mvn clean compile" + } + } + stage('Analysis using SonarQube') { + steps { + sh ''' + ${SCANNER_HOME}/bin/sonar-scanner \ + -Dsonar.projectKey=shopping-cart \ + -Dsonar.projectName=shopping-cart \ + -Dsonar.java.binaries=target/classes \ + -Dsonar.host.url=http://20.244.106.132:9000 \ + -Dsonar.login= + ''' + } + } + stage('Scan using OWASP') { + steps { + dependencyCheck additionalArguments: '--scan ./', odcInstallation: 'DP' + dependencyCheckPublisher pattern: '**/dependency-check-report.xml' + } + } + stage('Build usin Maven') { + steps { + sh "mvn clean install -DskipTests=True" + } + } + stage('Build and Push on Docker') { + steps { + withDockerRegistry(credentialsId: '', url: 'https://index.docker.io/v1/') { + sh "docker build -t shopping:latest -f docker/Dockerfile ." + sh "docker tag shopping:latest /shopping:latest" + sh "docker push /shopping:latest" + } + } + } + stage('Trigger CD') { + steps { + build job: 'CD-Pipeline', wait: true + } + } + } +} diff --git a/Jenkins/Readme.md b/Jenkins/Readme.md new file mode 100644 index 00000000..fff28fbb --- /dev/null +++ b/Jenkins/Readme.md @@ -0,0 +1,79 @@ +# 🛒 Ekart - CI Pipeline + +This repository implements a **Continuous Integration (CI) pipeline** for a Java-based shopping cart application using Jenkins, Maven, SonarQube, OWASP Dependency-Check, and Docker. + +--- + +## 📦 Tech Stack + +- **Jenkins** – Automation server for CI/CD. +- **Maven** – Java build and dependency management. +- **SonarQube** – Static code analysis and quality gate checks. +- **OWASP Dependency-Check** – Detects vulnerabilities in dependencies. +- **Docker** – Containerization for consistent deployments. +- **GitHub** – Source code hosting. +- **Docker Hub** – Image registry for Docker builds. + +--- + +## 🔁 Pipeline Stages + +### 1. **Git Checkout** +- Clones the `main` branch from the Ekart repository. + +### 2. **Compile using Maven** +- Runs `mvn clean compile` to compile the Java application. + +### 3. **SonarQube Analysis** +- Performs static code analysis using SonarQube. +- Publishes quality metrics like code smells, bugs, and coverage. + +### 4. **OWASP Dependency-Check** +- Scans project dependencies for known vulnerabilities. +- Generates and publishes a detailed security report. + +### 5. **Build using Maven** +- Builds the project and generates the final JAR/WAR. +- Skips running tests in this stage (`-DskipTests=true`). + +### 6. **Docker Build & Push** +- Builds a Docker image from the `docker/Dockerfile`. +- Tags and pushes the image to Docker Hub under `/shopping:latest`. + +### 7. **Trigger CD Pipeline** +- Triggers a downstream CD pipeline (`CD-Pipeline`) to handle deployment. + +--- + +## ⚙️ Prerequisites + +Make sure your Jenkins server has the following: + +- Java 11 (`jdk11`) installed and configured. +- Maven 3 (`maven3`) installed. +- SonarQube server accessible (e.g., `http://20.244.106.132:9000`). +- SonarQube authentication token stored in Jenkins Credentials. +- Docker installed on the Jenkins agent. +- Docker Hub credentials stored in Jenkins. +- OWASP Dependency-Check plugin installed and configured (`odcInstallation: 'DP'`). + +--- + +## 🔐 Secure Credential Management + +- Replace hardcoded SonarQube tokens with Jenkins **Credentials (Secret Text)**. +- Use `withCredentials` block for secure usage in pipeline scripts. + +--- +![](assets/diagram.png) +![](assets/1.png) +![](assets/7.png) +![](assets/6.png) +![](assets/10.png) +![](assets/5.png) +![](assets/2.png) +![](assets/3.png) +![](assets/4.png) + + + diff --git a/Jenkins/assets/1.png b/Jenkins/assets/1.png new file mode 100644 index 00000000..94119ed9 Binary files /dev/null and b/Jenkins/assets/1.png differ diff --git a/Jenkins/assets/10.png b/Jenkins/assets/10.png new file mode 100644 index 00000000..2a096d76 Binary files /dev/null and b/Jenkins/assets/10.png differ diff --git a/Jenkins/assets/11.png b/Jenkins/assets/11.png new file mode 100644 index 00000000..bf989c2f Binary files /dev/null and b/Jenkins/assets/11.png differ diff --git a/Jenkins/assets/12.png b/Jenkins/assets/12.png new file mode 100644 index 00000000..6148280b Binary files /dev/null and b/Jenkins/assets/12.png differ diff --git a/Jenkins/assets/13.png b/Jenkins/assets/13.png new file mode 100644 index 00000000..01b326b1 Binary files /dev/null and b/Jenkins/assets/13.png differ diff --git a/Jenkins/assets/2.png b/Jenkins/assets/2.png new file mode 100644 index 00000000..48854b6a Binary files /dev/null and b/Jenkins/assets/2.png differ diff --git a/Jenkins/assets/3.png b/Jenkins/assets/3.png new file mode 100644 index 00000000..66cb5b71 Binary files /dev/null and b/Jenkins/assets/3.png differ diff --git a/Jenkins/assets/4.png b/Jenkins/assets/4.png new file mode 100644 index 00000000..61a4a1da Binary files /dev/null and b/Jenkins/assets/4.png differ diff --git a/Jenkins/assets/5.png b/Jenkins/assets/5.png new file mode 100644 index 00000000..8de8a0b2 Binary files /dev/null and b/Jenkins/assets/5.png differ diff --git a/Jenkins/assets/6.png b/Jenkins/assets/6.png new file mode 100644 index 00000000..01074f7e Binary files /dev/null and b/Jenkins/assets/6.png differ diff --git a/Jenkins/assets/7.png b/Jenkins/assets/7.png new file mode 100644 index 00000000..bc898ca2 Binary files /dev/null and b/Jenkins/assets/7.png differ diff --git a/Jenkins/assets/8.png b/Jenkins/assets/8.png new file mode 100644 index 00000000..06ffe9c3 Binary files /dev/null and b/Jenkins/assets/8.png differ diff --git a/Jenkins/assets/9.png b/Jenkins/assets/9.png new file mode 100644 index 00000000..d06fd3d3 Binary files /dev/null and b/Jenkins/assets/9.png differ diff --git a/Jenkins/assets/diagram.png b/Jenkins/assets/diagram.png new file mode 100644 index 00000000..c6548154 Binary files /dev/null and b/Jenkins/assets/diagram.png differ diff --git a/Jenkins/assets/test b/Jenkins/assets/test new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Jenkins/assets/test @@ -0,0 +1 @@ +