Skip to content

Harsh971/JPetStore-CICD

 
 

Repository files navigation

JPetStore CICD

JPetStore 6 is a full web application built on top of MyBatis 3, Spring 5 and Stripes.

Essential Jenkins Plugins

  • jdk : Eclipse Temurin installer
  • sonar : SonarQube Scanner
  • owasp : OWASP Dependency-Check
  • docker : Docker, Docker Pipeline

Configuration of Plugins

Configure Plugins :

  • Manage Jenkins > Global Tool Configuration

JDK Installation

  • Name : jdk17
  • Install Automatically > Install from adoptium.net > Version 17

SonarQube Scanner installations

  • Name : sonar-scanner
  • Install Automatically > Version (Default)

Maven installations

  • Name : maven3
  • Install Automatically > Version 3.6.0

Dependency-Check installations

  • Name : DP
  • Install Automatically > Install from github.com > dependency-check 6.5.1

Docker installations

  • Name : docker
  • Install Automatically > Version (latest)

Initiating SonarQube

  • for the stage named : "SonarQube Analysis" we need to have sonarqube running so we will do it using Docker Command :
    docker run -d --name sonar -p 9000:9000 sonarqube:lts-community

Jenkins File :

pipeline {
    agent any
	
	tools{
		jdk 'jdk17'
		maven 'maven3'
	}
	
	environment {
		SCANNER_HOME= tool 'sonar-scanner'
	}

    stages {
        stage('Git Checkout') {
            steps {
                git changelog: false, poll: false, url: 'https://github.com/Harsh971/JPetStore-CICD.git'
            }
        }
		stage('Maven Compile') {
            steps {
                sh "mvn clean compile"
            }
        }
		stage('SonarQube Analysis') {
            steps {
                sh ''' $SCANNER_HOME/bin/sonar-scanner \
				-Dsonar.host.url=http://<IP>:9000 \
				-Dsonar.login=<SonarQube TOKEN> \
				-Dsonar.projectName=petstore \
				-Dsonar.java.binaries=. \
				-Dsonar.projectKey=petstore '''
            }
        }
		stage('OWASP Dependency Check') {
            steps {
                dependencyCheck additionalArguments: '--scan ./', odcInstallation: 'DP'
				dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
            }
        }
        stage('Maven Build') {
            steps {
                sh "mvn clean install"
            }
        }
		stage('Build and Push Docker Image') {
            steps {
                script{
					withDockerRegistry(credentialsId: 'DockerHub', toolName: 'docker') {
						sh "docker build -t petstore ."
						sh "docker tag petstore harsh0369/petstore:latest"
						sh "docker push harsh0369/petstore:latest"
					}
				}				
            }
        }
		stage('Deploy Docker Image') {
            steps {
                script{
					withDockerRegistry(credentialsId: 'DockerHub', toolName: 'docker') {
						sh "docker run -d -p 8081:8080 harsh0369/petstore:latest"
					}
				}				
            }
        }
    }
}

Output Snapshots :



Source Credits :

Original Source Code : Click Here Tutorial Reference : Click Here

Feedback

Your feedback is valuable! If you have suggestions for improving existing content or ideas for new additions, please open an issue or reach out to the repository maintainers. If you have any other feedbacks, you can reach out to us at [email protected]

Connect with Me

HarshThakkar971    harsh-thakkar-7764bb1a4    harsh_thakkar09

Releases

No releases published

Packages

No packages published

Languages

  • Java 92.9%
  • HTML 3.6%
  • CSS 3.4%
  • Dockerfile 0.1%