-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile5
More file actions
105 lines (90 loc) · 2.61 KB
/
Copy pathJenkinsfile5
File metadata and controls
105 lines (90 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
pipeline {
agent {
docker {
image 'docker:20.10.8-dind'
args '--privileged -v /var/run/docker.sock:/var/run/docker.sock'
}
}
environment {
SONAR_TOKEN = credentials('SONAR_TOKEN')
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/mekaizen/sdtest.git'
}
}
stage('Build with Maven') {
steps {
script {
// Run Maven inside a separate container
docker.image('maven:3.9.8-eclipse-temurin-21').inside {
sh 'mvn clean package'
}
}
}
}
stage('Run Application') {
steps {
script {
// Build and run your application from your existing Dockerfile
sh '''
docker build -t doc18/sdlc-app .
docker run --network jenkins-sonar-network -d --name app -p 8084:8084 doc18/sdlc-app
sleep 20
'''
}
}
}
stage('Check Application Logs') {
steps {
script {
sh 'docker logs app'
}
}
}
stage('Verify Application Running') {
steps {
script {
sh '''
curl -I http://localhost:8084 || {
echo "Application is not running!"
docker logs app
exit 1
}
'''
}
}
}
stage('ZAP Security Scan') {
steps {
script {
// Run ZAP security scan against the running application
sh '''
docker run --network jenkins-sonar-network zaproxy/zap-stable zap-baseline.py -t http://localhost:8084 -r zap-report.html
'''
}
}
}
stage('Post ZAP Scan Actions') {
steps {
archiveArtifacts artifacts: 'zap-report.html', allowEmptyArchive: true
}
}
}
post {
success {
echo 'Build, test, and ZAP scan passed'
}
failure {
echo 'Build failed'
}
always {
script {
sh '''
docker stop app && docker rm app
'''
}
}
}
}