mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 23:05:49 +00:00
Modified Jenkinsfile for testing.
This commit is contained in:
parent
5259d1d352
commit
6b0a0777f4
2 changed files with 34 additions and 22 deletions
|
@ -12,7 +12,7 @@ COPY mvnw pom.xml ./
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
|
||||||
# Package the application
|
# Package the application
|
||||||
RUN ./mvnw clean package
|
RUN ./mvnw clean package -DskipTests
|
||||||
|
|
||||||
# Copy the JAR file to the app directory
|
# Copy the JAR file to the app directory
|
||||||
COPY target/*.jar app.jar
|
COPY target/*.jar app.jar
|
||||||
|
|
52
Jenkinsfile
vendored
52
Jenkinsfile
vendored
|
@ -2,7 +2,8 @@ pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
DOCKER_CREDENTIALS_ID = 'your-docker-credentials-id' // Replace with your actual Docker credentials ID
|
SONARQUBE_URL = 'http://sonarqube:9000'
|
||||||
|
SONARQUBE_CREDENTIALS_ID = 'admin'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
@ -11,39 +12,50 @@ pipeline {
|
||||||
checkout scm
|
checkout scm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
sh './mvnw clean install'
|
||||||
sh './mvnw clean package'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
stage('Build Docker Image') {
|
stage('SonarQube Analysis') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
withSonarQubeEnv('SonarQube') {
|
||||||
// Build the Docker image
|
sh './mvnw sonar:sonar -Dsonar.projectKey=spring-petclinic'
|
||||||
sh 'docker build -t petclinic:latest .'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Push Docker Image') {
|
|
||||||
|
stage('OWASP ZAP') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
sh '''
|
||||||
// Push the Docker image to a registry
|
docker run --rm -v $(pwd)/zap-report:/zap/wrk:rw \
|
||||||
docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_CREDENTIALS_ID}") {
|
-t owasp/zap2docker-stable zap-baseline.py -t http://petclinic:8080 \
|
||||||
sh 'docker tag petclinic:latest your-docker-username/petclinic:latest'
|
-g gen.conf -r zap-report.html
|
||||||
sh 'docker push your-docker-username/petclinic:latest'
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
stage('Publish ZAP Report') {
|
||||||
stage('Deploy') {
|
|
||||||
steps {
|
steps {
|
||||||
script {
|
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'zap-report', reportFiles: 'zap-report.html', reportName: 'OWASP ZAP Report'])
|
||||||
// Deploy the application using Docker Compose
|
|
||||||
sh 'docker-compose up -d'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Deploy to Production') {
|
||||||
|
steps {
|
||||||
|
sh 'ansible-playbook -i inventory/production deploy.yml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
echo 'Pipeline completed successfully!'
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo 'Pipeline failed.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue