From ce92d0bca2d967fc4e1c05e9f658fdddb5997cab Mon Sep 17 00:00:00 2001 From: Lihan Date: Sat, 27 Jul 2024 01:52:53 -0400 Subject: [PATCH] Latest Jenkinsfile --- Jenkinsfile | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bc90f0734..2b10cc3cf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,26 +10,33 @@ pipeline { stages { stage('Checkout') { steps { - git url: 'https://github.com/CChariot/spring-petclinic.git', branch: 'FinalProject_main', credentialsId: 'github-token' + script { + echo "Checking out code..." + git url: 'https://github.com/CChariot/spring-petclinic.git', branch: 'FinalProject_main', credentialsId: 'github-token' + } } } stage('Build Docker Image') { steps { script { + echo "Building Docker Image..." dockerImage = docker.build("spring-petclinic") + echo "Docker Image built: ${dockerImage.id}" } } } stage('SonarQube Analysis') { steps { - withSonarQubeEnv('SonarQube') { - script { + script { + echo "Starting SonarQube analysis..." + withSonarQubeEnv('SonarQube') { dockerImage.inside("-u root") { sh './mvnw sonar:sonar -Dsonar.projectKey=spring-petclinic' } } + echo "SonarQube analysis completed." } } } @@ -37,9 +44,11 @@ pipeline { stage('Build Application') { steps { script { + echo "Building application..." dockerImage.inside("-u root") { sh './mvnw clean package -DskipTests' } + echo "Application build completed." } } } @@ -47,32 +56,46 @@ pipeline { stage('Run Application') { steps { script { + echo "Running application..." dockerImage.inside("-u root") { sh 'java -jar target/*.jar' } + echo "Application is running." } } } stage('OWASP ZAP') { steps { - sh ''' - docker run --rm -v $(pwd)/zap-report:/zap/wrk:rw \ - owasp/zap2docker-stable zap-baseline.py -t http://localhost:8080 \ - -g gen.conf -r zap-report.html - ''' + script { + echo "Running OWASP ZAP..." + sh ''' + docker run --rm -v $(pwd)/zap-report:/zap/wrk:rw \ + owasp/zap2docker-stable zap-baseline.py -t http://localhost:8080 \ + -g gen.conf -r zap-report.html + ''' + echo "OWASP ZAP analysis completed." + } } } stage('Publish ZAP Report') { steps { - publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'zap-report', reportFiles: 'zap-report.html', reportName: 'OWASP ZAP Report']) + script { + echo "Publishing OWASP ZAP report..." + publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'zap-report', reportFiles: 'zap-report.html', reportName: 'OWASP ZAP Report']) + echo "OWASP ZAP report published." + } } } stage('Deploy to Production') { steps { - sh 'ansible-playbook -i inventory/production deploy.yml' + script { + echo "Deploying to production..." + sh 'ansible-playbook -i inventory/production deploy.yml' + echo "Deployment to production completed." + } } } } @@ -82,6 +105,7 @@ pipeline { script { try { if (dockerImage != null) { + echo "Stopping and removing Docker Image..." dockerImage.stop() dockerImage.remove() } @@ -97,4 +121,4 @@ pipeline { echo 'Pipeline failed.' } } -} \ No newline at end of file +}