From 9844afec9445c3588dfcb639b82a33845256792c Mon Sep 17 00:00:00 2001 From: kiranthomas123 <64312184+kiranthomas123@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:12:49 +0530 Subject: [PATCH] Create JenkinsFile --- JenkinsFile | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 JenkinsFile diff --git a/JenkinsFile b/JenkinsFile new file mode 100644 index 000000000..caef71209 --- /dev/null +++ b/JenkinsFile @@ -0,0 +1,57 @@ +pipeline { + agent any + + environment { + MAVEN_HOME = tool 'maven' + DOCKER_REGISTRY = 'your-jfrog-url' + DOCKER_IMAGE = 'spring-petclinic' + JFROG_REPO = 'your-jfrog-repo' + CHECKSTYLE_REPORT = 'checkstyle-result.xml' + JACOCO_REPORT = 'target/site/jacoco/jacoco.xml' + SONAR_URL = 'http://localhost:9091' // Adjust URL according to your SonarQube instance + } + + stages { + stage('SCM Clone') { + steps { + git branch: 'main', url: 'https://github.com/NimalDas/spring-petclinic.git' + } + } + + stage('Maven Build') { + steps { + sh "${MAVEN_HOME}/bin/mvn clean package" + } + } + stage('Checkstyle') { + steps { + sh "${MAVEN_HOME}/bin/mvn checkstyle:checkstyle" + junit allowEmptyResults: true, testResults: '**/${CHECKSTYLE_REPORT}' + } + } + stage('Unit Tests & JaCoCo') { + steps { + sh "${MAVEN_HOME}/bin/mvn test jacoco:report" + junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml' + jacoco(execPattern: 'target/**/*.exec', classPattern: '**/target/classes', sourcePattern: '**/src/main/java') + } + } + + stage('SonarQube Analysis') { + steps { + withCredentials([string(credentialsId: 'sonartoken', variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonarqube') { + sh "${MAVEN_HOME}/bin/mvn sonar:sonar -Dsonar.host.url=${SONAR_URL} -Dsonar.login=${SONAR_TOKEN}" + } + } + } + } + stage('Docker Build & Push') { + steps { + script { + docker.build("${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${env.BUILD_NUMBER}") + } + } + } + } +}