forked from Santhoshsk1802/microservices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
154 lines (154 loc) · 6.92 KB
/
Jenkinsfile
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
152
153
154
pipeline {
agent any
stages {
stage('SCM Checkout'){
steps {
git branch: 'main', url: 'https://github.com/naresh26git/microservices.git'
sh 'ls'
}
}
stage('SonarQube Analysis') {
steps {
parallel (
'node application': {
script {
dir('cart-microservice-nodejs') {
def scannerHome = tool 'sonarscanner4'
withSonarQubeEnv('sonar-pro') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=cart-nodejs"
}
}
dir('ui-web-app-reactjs') {
def scannerHome = tool 'sonarscanner4';
withSonarQubeEnv('sonar-pro') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=ui-reactjs"
}
}
}
},
'spring boot application': {
script {
dir('offers-microservice-spring-boot') {
def mvn = tool 'maven3';
withSonarQubeEnv('sonar-pro') {
sh "${mvn}/bin/mvn clean verify sonar:sonar -Dsonar.projectKey=offers-spring-boot -Dsonar.projectName=offers-spring-boot"
}
}
dir('shoes-microservice-spring-boot') {
def mvn = tool 'maven3';
withSonarQubeEnv('sonar-pro') {
sh "${mvn}/bin/mvn clean verify sonar:sonar -Dsonar.projectKey=shoe-spring-boot -Dsonar.projectName=shoes-spring-boot"
}
}
dir('zuul-api-gateway') {
def mvn = tool 'maven3';
withSonarQubeEnv('sonar-pro') {
sh "${mvn}/bin/mvn clean verify sonar:sonar -Dsonar.projectKey=zuul-api -Dsonar.projectName=zuul-api"
}
}
}
},
'python app': {
script{
dir('wishlist-microservice-python') {
def scannerHome = tool 'sonarscanner4';
withSonarQubeEnv('sonar-pro') {
sh """/var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarscanner4/bin/sonar-scanner \
-D sonar.projectVersion=1.0-SNAPSHOT \
-D sonar.sources=. \
-D sonar.login=admin \
-D sonar.password=admin123 \
-D sonar.projectKey=project \
-D sonar.projectName=wishlist-py \
-D sonar.inclusions=index.py \
-D sonar.sourceEncoding=UTF-8 \
-D sonar.language=python \
-D sonar.host.url=http://13.232.29.132:9000/"""
}
}
}
}
)
}
}
stage ('Build Docker Image and push'){
steps {
parallel (
'docker login': {
withCredentials([string(credentialsId: 'dockerPass', variable: 'dockerPassword')]) {
sh "docker login -u comdevops -p ${dockerPassword}"
}
},
'ui-web-app-reactjs': {
dir('ui-web-app-reactjs'){
sh """
docker build -t comdevops/ui:v1 .
docker push comdevops/ui:v1
docker rmi comdevops/ui:v1
"""
}
},
'zuul-api-gateway' : {
dir('zuul-api-gateway'){
sh """
docker build -t comdevops/api:v1 .
docker push comdevops/api:v1
docker rmi comdevops/api:v1
"""
}
},
'offers-microservice-spring-boot': {
dir('offers-microservice-spring-boot'){
sh """
docker build -t comdevops/spring:v1 .
docker push comdevops/spring:v1
docker rmi comdevops/spring:v1
"""
}
},
'shoes-microservice-spring-boot': {
dir('shoes-microservice-spring-boot'){
sh """
docker build -t comdevops/spring:v2 .
docker push comdevops/spring:v2
docker rmi comdevops/spring:v2
"""
}
},
'cart-microservice-nodejs': {
dir('cart-microservice-nodejs'){
sh """
docker build -t comdevops/ui:v2 .
docker push comdevops/ui:v2
docker rmi comdevops/ui:v2
"""
}
},
'wishlist-microservice-python': {
dir('wishlist-microservice-python'){
sh """
docker build -t comdevops/python:v1 .
docker push comdevops/python:v1
docker rmi comdevops/python:v1
"""
}
}
)
}
}
stage ('Deploy on k8s'){
steps{
parallel (
'deploy on k8s': {
script {
withKubeCredentials(kubectlCredentials: [[ credentialsId: 'kubernetes', namespace: 'ms' ]]) {
sh 'kubectl get ns'
sh 'kubectl apply -f kubernetes/yamlfile'
}
}
}
)
}
}
}
}