Modified Jenkinsfile for testing.

This commit is contained in:
Lihan 2024-07-27 01:28:13 -04:00
parent 6b0a0777f4
commit c744a71a5f

36
Jenkinsfile vendored
View file

@ -13,25 +13,49 @@ pipeline {
} }
} }
stage('Build') { stage('Build Docker Image') {
steps { steps {
sh './mvnw clean install' script {
dockerImage = docker.build("spring-petclinic")
}
} }
} }
stage('SonarQube Analysis') { stage('SonarQube Analysis') {
steps { steps {
withSonarQubeEnv('SonarQube') { withSonarQubeEnv('SonarQube') {
script {
dockerImage.inside("-u root") {
sh './mvnw sonar:sonar -Dsonar.projectKey=spring-petclinic' sh './mvnw sonar:sonar -Dsonar.projectKey=spring-petclinic'
} }
} }
} }
}
}
stage('Build Application') {
steps {
script {
dockerImage.inside("-u root") {
sh './mvnw clean package -DskipTests'
}
}
}
}
stage('Run Application') {
steps {
script {
dockerImage.run("-p 8080:8080 --name spring-petclinic")
}
}
}
stage('OWASP ZAP') { stage('OWASP ZAP') {
steps { steps {
sh ''' sh '''
docker run --rm -v $(pwd)/zap-report:/zap/wrk:rw \ docker run --rm -v $(pwd)/zap-report:/zap/wrk:rw \
-t owasp/zap2docker-stable zap-baseline.py -t http://petclinic:8080 \ owasp/zap2docker-stable zap-baseline.py -t http://localhost:8080 \
-g gen.conf -r zap-report.html -g gen.conf -r zap-report.html
''' '''
} }
@ -51,6 +75,12 @@ pipeline {
} }
post { post {
always {
script {
dockerImage.stop()
dockerImage.remove()
}
}
success { success {
echo 'Pipeline completed successfully!' echo 'Pipeline completed successfully!'
} }