Modified Jenkinsfile for testing.

This commit is contained in:
Lihan 2024-07-27 00:37:51 -04:00
parent 5259d1d352
commit 6b0a0777f4
2 changed files with 34 additions and 22 deletions

View file

@ -12,7 +12,7 @@ COPY mvnw pom.xml ./
COPY src ./src
# Package the application
RUN ./mvnw clean package
RUN ./mvnw clean package -DskipTests
# Copy the JAR file to the app directory
COPY target/*.jar app.jar

52
Jenkinsfile vendored
View file

@ -2,7 +2,8 @@ pipeline {
agent any
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 {
@ -11,39 +12,50 @@ pipeline {
checkout scm
}
}
stage('Build') {
steps {
script {
sh './mvnw clean package'
sh './mvnw clean install'
}
}
}
stage('Build Docker Image') {
stage('SonarQube Analysis') {
steps {
script {
// Build the Docker image
sh 'docker build -t petclinic:latest .'
withSonarQubeEnv('SonarQube') {
sh './mvnw sonar:sonar -Dsonar.projectKey=spring-petclinic'
}
}
}
stage('Push Docker Image') {
stage('OWASP ZAP') {
steps {
script {
// Push the Docker image to a registry
docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_CREDENTIALS_ID}") {
sh 'docker tag petclinic:latest your-docker-username/petclinic:latest'
sh 'docker push your-docker-username/petclinic:latest'
sh '''
docker run --rm -v $(pwd)/zap-report:/zap/wrk:rw \
-t owasp/zap2docker-stable zap-baseline.py -t http://petclinic:8080 \
-g gen.conf -r zap-report.html
'''
}
}
}
}
stage('Deploy') {
stage('Publish ZAP Report') {
steps {
script {
// Deploy the application using Docker Compose
sh 'docker-compose up -d'
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'zap-report', reportFiles: 'zap-report.html', reportName: 'OWASP ZAP Report'])
}
}
stage('Deploy to Production') {
steps {
sh 'ansible-playbook -i inventory/production deploy.yml'
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed.'
}
}
}