diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..e909ebcf0 --- /dev/null +++ b/Jenkinsfile @@ -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}" + + } + } + } + } + + } +} diff --git a/pom.xml b/pom.xml index a9bbd2959..9a085c865 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,11 @@ + + org.jacoco + jacoco-maven-plugin + 0.8.6 + org.springframework.boot spring-boot-starter-actuator @@ -143,7 +148,13 @@ - + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.9.0.2155 + + + org.apache.maven.plugins maven-enforcer-plugin @@ -437,10 +448,22 @@ + + org.owasp + dependency-check-maven + INSERT_VERSION_HERE + + + + check + + + + - \ No newline at end of file +