added jenkins file and modified pom

This commit is contained in:
prasannakumar 2024-06-16 13:36:49 +05:30
parent d8fcd11e67
commit 751ce8e646
2 changed files with 88 additions and 2 deletions

63
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,63 @@
pipeline {
agent any
tools {
jdk 'jdk17'
maven 'maven3'
}
environment {
SONAR_AUTH_TOKEN = credentials('sonarfile') // Assumes you have stored your token in Jenkins Credentials
}
stages {
stage('compile ') {
steps {
sh 'mvn compile'
}
}
stage('SonarQube Analysis') {
steps {
script {
// Run Maven with SonarQube plugin for analysis
withSonarQubeEnv('SonarQubeScanner') { // 'SonarQubeScanner' is the name of the SonarQube server configured in Jenkins
sh """
mvn sonar:sonar -Dsonar.login=${SONAR_AUTH_TOKEN} \
-Dsonar.projectName=spring-petclinic \
-Dsonar.java.binaries=. \
-Dsonar.projectKey=spring-petclinic
"""
//mvn sonar:sonar sonar maven plugin command
//Command: $SCANNER_HOME/bin/sonar-scanner standalone sonarqub scanner command
}
}
}
}
stage('Maven Package') {
steps {
sh 'mvn clean package -DskipTests'
}
}
stage('OWASP Dependency-Check') {
steps {
dependencyCheck additionalArguments: '--scan target/', odcInstallation: 'OWASP Check'
}
}
stage('Build & push Docker Image') {
when {
branch 'Release'
}
steps {
script {
withDockerRegistry(credentialsId: 'c9b058e5-bfe6-41f8-9b5d-dc0b0d2955ac', toolName: 'docker') {
sh "docker build -t prasannakumarsinganamalla431/petclinic:${BUILD_NUMBER} -f .devcontainer/Dockerfile ."
sh "docker push prasannakumarsinganamalla431/petclinic:${BUILD_NUMBER}"
}
}
}
}
}
}

23
pom.xml
View file

@ -39,6 +39,11 @@
<dependencies>
<!-- Spring and Spring Boot dependencies -->
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
@ -143,6 +148,12 @@
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.0.2155</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
@ -436,6 +447,18 @@
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>INSERT_VERSION_HERE</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>