JPetStore 6 is a full web application built on top of MyBatis 3, Spring 5 and Stripes.
jdk
: Eclipse Temurin installersonar
: SonarQube Scannerowasp
: OWASP Dependency-Checkdocker
: Docker, Docker Pipeline
- Manage Jenkins > Global Tool Configuration
- Name : jdk17
- Install Automatically > Install from adoptium.net > Version 17
- Name : sonar-scanner
- Install Automatically > Version (Default)
- Name : maven3
- Install Automatically > Version 3.6.0
- Name : DP
- Install Automatically > Install from github.com > dependency-check 6.5.1
- Name : docker
- Install Automatically > Version (latest)
- 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
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"
}
}
}
}
}
}
Original Source Code : Click Here Tutorial Reference : Click Here
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]