mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Latest Jenkinsfile
This commit is contained in:
parent
40819bc102
commit
ce92d0bca2
1 changed files with 35 additions and 11 deletions
44
Jenkinsfile
vendored
44
Jenkinsfile
vendored
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue