-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
151 lines (129 loc) · 4.54 KB
/
Jenkinsfile
File metadata and controls
151 lines (129 loc) · 4.54 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
pipeline {
agent any
environment {
SONAR_HOST_URL = 'http://localhost:9000'
NODE_OPTIONS = '--dns-result-order=ipv4first'
NPM_CONFIG_REGISTRY = 'https://registry.npmjs.org/'
}
parameters {
string(name: 'FRONTEND_DOCKER_TAG', defaultValue: 'latest', description: 'Frontend image tag')
string(name: 'BACKEND_DOCKER_TAG', defaultValue: 'latest', description: 'Backend image tag')
}
stages {
stage('Workspace Cleanup') {
steps {
cleanWs()
}
}
stage('Checkout Code') {
steps {
git branch: 'main', url: 'https://github.com/dvanhu/Wanderlust-Mega-DevSecOps-Project.git'
}
}
stage('Install Dependencies') {
steps {
retry(2) {
sh '''
npm config set registry $NPM_CONFIG_REGISTRY
npm config set fetch-retries 5
cd backend
npm install --no-audit --prefer-offline
cd ../frontend
npm install --no-audit --prefer-offline
'''
}
}
}
stage('OWASP Dependency Check') {
steps {
sh '''
/opt/dependency-check/bin/dependency-check.sh \
--scan . \
--format XML \
--out . \
--data /opt/dependency-check/data \
--disableOssIndex \
--disableYarnAudit \
|| true
'''
}
}
stage('Trivy Filesystem Scan') {
steps {
sh 'trivy fs . --format table'
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh '''
sonar-scanner \
-Dsonar.projectKey=wanderlust \
-Dsonar.sources=. \
-Dsonar.host.url=$SONAR_HOST_URL
'''
}
}
}
stage('Build Docker Images') {
steps {
sh '''
docker build -t wanderlust-backend:${BACKEND_DOCKER_TAG} ./backend
docker build -t wanderlust-frontend:${FRONTEND_DOCKER_TAG} ./frontend
'''
}
}
stage('Trivy Image Scan') {
steps {
sh '''
trivy image wanderlust-backend:${BACKEND_DOCKER_TAG}
trivy image wanderlust-frontend:${FRONTEND_DOCKER_TAG}
'''
}
}
stage('Docker Push') {
steps {
withCredentials([usernamePassword(
credentialsId: 'docker-cred',
usernameVariable: 'DOCKER_USER',
passwordVariable: 'DOCKER_PASS'
)]) {
sh '''
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker tag wanderlust-backend:${BACKEND_DOCKER_TAG} $DOCKER_USER/wanderlust-backend:${BACKEND_DOCKER_TAG}
docker tag wanderlust-frontend:${FRONTEND_DOCKER_TAG} $DOCKER_USER/wanderlust-frontend:${FRONTEND_DOCKER_TAG}
docker push $DOCKER_USER/wanderlust-backend:${BACKEND_DOCKER_TAG}
docker push $DOCKER_USER/wanderlust-frontend:${FRONTEND_DOCKER_TAG}
'''
}
}
}
stage('Deploy to Kubernetes') {
steps {
sh '''
echo "Deploying to Kubernetes..."
export KUBECONFIG=/var/lib/jenkins/config
kubectl set image deployment/backend-deployment \
backend=dvanhu/wanderlust-backend:${BACKEND_DOCKER_TAG} \
-n wanderlust
kubectl set image deployment/frontend-deployment \
frontend=dvanhu/wanderlust-frontend:${FRONTEND_DOCKER_TAG} \
-n wanderlust
kubectl rollout status deployment/backend-deployment -n wanderlust
kubectl rollout status deployment/frontend-deployment -n wanderlust
'''
}
}
}
post {
always {
archiveArtifacts artifacts: '*.xml', allowEmptyArchive: true
}
success {
echo "✅ FULL CI/CD SUCCESS 🚀"
}
failure {
echo "❌ Pipeline failed"
}
}
}