Create JenkinsFile

This commit is contained in:
kiranthomas123 2024-03-24 18:12:49 +05:30 committed by GitHub
parent 516722647a
commit 9844afec94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

57
JenkinsFile Normal file
View file

@ -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}")
}
}
}
}
}