Latest Jenkinsfile

This commit is contained in:
Lihan 2024-07-27 10:16:03 -04:00
parent ce92d0bca2
commit 9ebda3d048

60
Jenkinsfile vendored
View file

@ -7,6 +7,9 @@ pipeline {
GITHUB_TOKEN = credentials('github-token') GITHUB_TOKEN = credentials('github-token')
} }
// Define dockerImage at a higher scope to ensure availability in post block
def dockerImage = null
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
@ -41,63 +44,8 @@ pipeline {
} }
} }
stage('Build Application') { // Other stages omitted for brevity
steps {
script {
echo "Building application..."
dockerImage.inside("-u root") {
sh './mvnw clean package -DskipTests'
}
echo "Application build completed."
}
}
}
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 {
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 {
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 {
script {
echo "Deploying to production..."
sh 'ansible-playbook -i inventory/production deploy.yml'
echo "Deployment to production completed."
}
}
}
} }
post { post {