-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile_bkp
344 lines (274 loc) · 10.6 KB
/
Jenkinsfile_bkp
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
def DEV_CMD = ""
def TEST_CMD = ""
def UAT_CMD = ""
def LIVE_CMD = ""
/**
* generte command server
* @method generateCMDForServer
* @Author_name G.Balakumaran
* @datetime 2019-06-23T19:26:30+0530
* @param serverName [description]
* @return [description]
*/
def generateCMDForServer(serverName){
/**
* Dev server Configuration
*/
def DEV_DEST = "/var/www/html/interface_dev"
def TEST_DEST = "/var/www/html/interface_test"
def UAT_DEST = "/var/www/html/interface_uat"
def LIVE_DEST = "/var/www/html/interface_live"
def COMMAND = ""
def DEST_DIR = ""
if(serverName == "DEV") {
DEST_DIR = "$DEV_DEST";
}
if(serverName == "TEST") {
DEST_DIR = "$TEST_DEST";
}
if(serverName == "UAT") {
DEST_DIR = "$UAT_DEST";
}
if(serverName == "LIVE") {
DEST_DIR = "$LIVE_DEST";
}
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
def files = new ArrayList(entry.affectedFiles)
for (int k = 0; k < files.size(); k++) {
def file = files[k]
println "Files List -> $file.path"
if(COMMAND != ""){
COMMAND = "$COMMAND && scp -o StrictHostKeyChecking=no $WORKSPACE/$file.path ubuntu@ec2-13-232-76-112.ap-south-1.compute.amazonaws.com:$DEST_DIR/$file.path"
}else{
COMMAND = "scp -o StrictHostKeyChecking=no $WORKSPACE/$file.path ubuntu@ec2-13-232-76-112.ap-south-1.compute.amazonaws.com:$DEST_DIR/$file.path"
}
}
}
}
return COMMAND
}
/**
* send email
* @method sendEmailNotification
* @Author_name G.Balakumaran
* @datetime 2019-06-23T19:28:36+0530
* @param subject subject
* @param body bosy
* @param to to
* @return void
*/
def sendEmailNotification(subject,body,serverName){
/**
* Dev server Configuration
*/
def DEV_EMAIL = "balakumaran.g@infinitisoftware.net"
def TO_EMAIL = ""
if(serverName == "DEV") {
TO_EMAIL = "$DEV_EMAIL";
}
emailext (
subject: subject,
body: body,
to: "$TO_EMAIL",
from: "balakumaran.raji@gmail.com"
)
}
/**
* create stages
*/
node {
stage("checkout") {
/**
* checking out
*/
println "Checking out...."
git url: 'https://github.com/balapkm/interface.git'
/**
* generate last commit changes
*/
println "Get last commit changes.."
DEV_CMD = generateCMDForServer("DEV")
TEST_CMD = generateCMDForServer("TEST")
UAT_CMD = generateCMDForServer("UAT")
LIVE_CMD = generateCMDForServer("LIVE")
println "$DEV_CMD"
println "$TEST_CMD"
println "$UAT_CMD"
println "$LIVE_CMD"
/**
* checking last commit is there
*/
if(DEV_CMD == "") {
error("No files are committed");
}
/**
* send start job emails
*/
println "Send Email Notification for start Job"
body = """Hi team,
The Job Name (${env.JOB_NAME} - ${env.BUILD_NUMBER}) is started successfully and refer below link about this job
${env.BUILD_URL}
"""
sendEmailNotification("Start Job '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
}
stage("Deploy - Development Server") {
println "$DEV_CMD"
/**
* Send Email Notification for team leader for apporval
*/
println "Send Email Notification team leader for apporval of file movement of development server.."
body = """Hi Team Leader,
Kindly review current version code and approve the file movement of development server?
Commit Changes - ${env.BUILD_URL}changes
Approve/Reject - ${env.BUILD_URL}input
"""
sendEmailNotification("Development Server approval - '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
/**
* approval for move file for development server
*/
timeout(time: 5, unit: 'DAYS') {
input message: 'Kindly review current version code and approve the file movement of development server?', ok: 'Approve', parameters: [string(defaultValue: '', description: '', name: 'Approve/Reject Reason', trim: false)], submitter: 'balakumaran'
}
/**
* move files into develpment server
*/
sshagent(credentials : ['Balakumaran']) {
sh "$DEV_CMD"
}
/**
* Migrate Database
*/
println "Start database Migration"
flywayrunner commandLineArgs: '', credentialsId: '29094ff4-b5ea-47ad-8491-6fdcd0756608', flywayCommand: 'migrate', installationName: 'Flyway', locations: "filesystem:$WORKSPACE/sql", url: 'jdbc:mysql://localhost:3306/interface_dev'
/**
* Success Messagae
*/
println "Success Messagae..!!"
body = """Hi Team Leader,
File Moved Successfully in development server
Console Log - ${env.BUILD_URL}console
"""
sendEmailNotification("Development Server File Moved Successfully - '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
}
stage("Deploy - Testing Server") {
println "$TEST_CMD"
/**
* Send Email Notification for Manager for apporval
*/
println "Send Email Notification Manager for apporval of file movement of testing server.."
body = """Dear Manager,
Kindly approve the file movement of testing server?
Commit Changes - ${env.BUILD_URL}changes
Approve/Reject - ${env.BUILD_URL}input
"""
sendEmailNotification("Testing Server approval - '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
/**
* approval for move file for development server
*/
timeout(time: 5, unit: 'DAYS') {
input message: 'Kindly approve the file movement of testing server?', ok: 'Approve', parameters: [string(defaultValue: '', description: '', name: 'Approve/Reject Reason', trim: false)], submitter: 'balakumaran'
}
/**
* move files into testing server
*/
sshagent(credentials : ['Balakumaran']) {
sh "$TEST_CMD"
}
/**
* Migrate Database
*/
println "Start database Migration"
flywayrunner commandLineArgs: '', credentialsId: '29094ff4-b5ea-47ad-8491-6fdcd0756608', flywayCommand: 'migrate', installationName: 'Flyway', locations: "filesystem:$WORKSPACE/sql", url: 'jdbc:mysql://localhost:3306/interface_test'
/**
* Success Messagae
*/
println "Success Messagae..!!"
body = """Hi Team Leader,
File Moved Successfully in Testing server
Console Log - ${env.BUILD_URL}console
"""
sendEmailNotification("Testing Server File Moved Successfully - '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
}
stage("Deploy - UAT Server") {
println "$UAT_CMD"
/**
* Send Email Notification for Manager for apporval
*/
println "Send Email Notification Testing Team for apporval of file movement of UAT server.."
body = """Dear Testing Team,
Kindly approve the file movement of UAT server?
Commit Changes - ${env.BUILD_URL}changes
Approve/Reject - ${env.BUILD_URL}input
"""
sendEmailNotification("UAT Server approval - '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
/**
* approval for move file for development server
*/
timeout(time: 5, unit: 'DAYS') {
input message: 'Kindly approve the file movement of UAT server?', ok: 'Approve', parameters: [string(defaultValue: '', description: '', name: 'Approve/Reject Reason', trim: false)], submitter: 'balakumaran'
}
/**
* move files into UAT server
*/
sshagent(credentials : ['Balakumaran']) {
sh "$UAT_CMD"
}
/**
* Migrate Database
*/
println "Start database Migration"
flywayrunner commandLineArgs: '', credentialsId: '29094ff4-b5ea-47ad-8491-6fdcd0756608', flywayCommand: 'migrate', installationName: 'Flyway', locations: "filesystem:$WORKSPACE/sql", url: 'jdbc:mysql://localhost:3306/interface_uat'
/**
* Success Messagae
*/
println "Success Messagae..!!"
body = """Hi Testing Team,
File Moved Successfully in UAT server
Console Log - ${env.BUILD_URL}console
"""
sendEmailNotification("UAT Server File Moved Successfully - '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
}
stage("Deploy - LIVE Server") {
println "$LIVE_CMD"
/**
* Send Email Notification for Manager for apporval
*/
println "Send Email Notification Client for apporval of file movement of LIVE server.."
body = """Dear Client,
Kindly approve the file movement of LIVE server?
Commit Changes - ${env.BUILD_URL}changes
Approve/Reject - ${env.BUILD_URL}input
"""
sendEmailNotification("LIVE Server approval - '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
/**
* approval for move file for development server
*/
timeout(time: 5, unit: 'DAYS') {
input message: 'Kindly approve the file movement of LIVE server?', ok: 'Approve', parameters: [string(defaultValue: '', description: '', name: 'Approve/Reject Reason', trim: false)], submitter: 'balakumaran'
}
/**
* move files into LVIVE server
*/
sshagent(credentials : ['Balakumaran']) {
sh "$LIVE_CMD"
}
/**
* Migrate Database
*/
println "Start database Migration"
flywayrunner commandLineArgs: '', credentialsId: '29094ff4-b5ea-47ad-8491-6fdcd0756608', flywayCommand: 'migrate', installationName: 'Flyway', locations: "filesystem:$WORKSPACE/sql", url: 'jdbc:mysql://localhost:3306/interface_live'
/**
* Success Messagae
*/
println "Success Messagae..!!"
body = """Dear Client,
File Moved Successfully in Live server
Console Log - ${env.BUILD_URL}console
"""
sendEmailNotification("Live Server File Moved Successfully- '${env.JOB_NAME} ${env.BUILD_NUMBER}'",body,"DEV")
}
}