forked from xebialabs/xl-release-kubernetes-helm-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
361 lines (360 loc) · 23.4 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
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
pipeline{
agent any
parameters {
choice(name: 'PRODUCT', choices: ['XL Release', 'XL Deploy'], description: 'Select the product to package')
choice(name: 'PLATFORM', choices: ['Onprem', 'EKS', 'Openshift_AWS','Openshift_Onprem'], description: 'Pick the platform to deploy the helm chart')
choice(name: 'INSTALL_CHART', choices: ['YES', 'NO'], description: 'Do you want to install the helm chart?')
}
options {
timeout(time: 10, unit: 'MINUTES')
}
environment {
BRANCH_NAME = "rabbitmq"
BRANCH_OPENSHIFT = "ENG-2678"
PRODUCT_NAME = "${params.PRODUCT}"
PLATFORM_NAME = "${params.PLATFORM}"
GIT_HUB_XLR_URL = "https://github.com/chandras-xl/xl-release-kubernetes-helm-chart.git"
GIT_HUB_XLD_URL = "https://github.com/chandras-xl/xl-deploy-kubernetes-helm-chart-1.git"
GIT_HUB_XLR_OPENSHIFT_URL = "https://github.com/chandras-xl/xl-release-kubernetes-helm-chart.git"
GIT_HUB_XLD_OPENSHIFT_URL = "https://github.com/chandras-xl/xl-deploy-kubernetes-helm-chart-1.git"
NEXUS_USER = "admin"
NEXUS_PASSWORD = credentials('NEXUS_SECRET')
NEXUS_URL_XLR = "http://nexus-appserver.digitalai-testing.com:8081/repository/XL_Release_Helm_Repo/"
NEXUS_URL_XLD = "http://nexus-appserver.digitalai-testing.com:8081/repository/XL_Deploy_Helm_Repo/"
NEXUS_URL_OC_XLR = "http://nexus-appserver.digitalai-testing.com:8081/repository/XL_Release_Openshift_Helm_Repo/"
NEXUS_URL_OC_XLD = "http://nexus-appserver.digitalai-testing.com:8081/repository/XL_Deploy_Openshift_Helm_Repo/"
XEBIALABS_DIST_USERNAME = "download"
XEBIALABS_DIST_PASSWORD = ""
XEBIALABS_DIST_XLR_URL = ""
XEBIALABS_DIST_XLD_URL = ""
XEBIALABS_DIST_OC_XLR_URL = ""
XEBIALABS_DIST_OC_XLD_URL = ""
HOST_NAME_XLR_ONPREM = "kublove-kn2.xebialabs.com"
HOST_NAME_XLD_ONPREM = "kublove-kn3.xebialabs.com"
HOST_NAME_XLR_EKS = "release-eks.digitalai-testing.com"
HOST_NAME_XLD_EKS = "deploy-eks.digitalai-testing.com"
HOST_NAME_XLR_OPENSHIFT = "release-openshift.apps.oc-devops.xldevinfra.com"
HOST_NAME_XLD_OPENSHIFT = "deploy-openshift.apps.oc-devops.xldevinfra.com"
STORAGE_CLASS_ONPREM = "nfs-client"
STORAGE_CLASS_EKS = "aws-efs"
LOADBALANCER = "LoadBalancer"
OPENSHIFT_AWS_CRED = credentials('OPENSHIFT_AWS_CRED')
OPENSHIFT_AWS_SERVER_URL = "https://api.oc-devops.xldevinfra.com:6443"
}
stages {
stage('Git checkout') {
steps {
script {
if ( env.PRODUCT_NAME == 'XL Release' && (env.PLATFORM_NAME == 'Onprem' | env.PLATFORM_NAME == 'EKS' )) {
try {
sh '''
echo Checking out the code for $PRODUCT_NAME $PLATFORM_NAME platform from $BRANCH_NAME branch
git clone -b $BRANCH_NAME $GIT_HUB_XLR_URL
echo "Git check out successful !!!"
'''
}catch(error) {
throw error
}
} else if ( env.PRODUCT_NAME == 'XL Deploy' && (env.PLATFORM_NAME == 'Onprem' | env.PLATFORM_NAME == 'EKS' )) {
try {
sh '''
echo Checking out the code for $PRODUCT_NAME $PLATFORM_NAME platform from $BRANCH_NAME branch
git clone -b $BRANCH_NAME $GIT_HUB_XLD_URL
echo "Git check out successful !!!"
'''
}catch(error) {
throw error
}
} else if ( env.PRODUCT_NAME == 'XL Release' && (env.PLATFORM_NAME == 'Openshift_Onprem' | env.PLATFORM_NAME == 'Openshift_AWS' )) {
try {
sh '''
echo Checking out the code for $PRODUCT_NAME $PLATFORM_NAME platform from $BRANCH_NAME branch
git clone -b $BRANCH_OPENSHIFT $GIT_HUB_XLR_OPENSHIFT_URL
echo "Git check out successful !!!"
'''
}catch(error) {
throw error
}
} else if ( env.PRODUCT_NAME == 'XL Deploy' && (env.PLATFORM_NAME == 'Openshift_Onprem' | env.PLATFORM_NAME == 'Openshift_AWS' )) {
try {
sh '''
echo Checking out the code for $PRODUCT_NAME $PLATFORM_NAME platform from $BRANCH_NAME branch
git clone -b $BRANCH_OPENSHIFT $GIT_HUB_XLD_OPENSHIFT_URL
echo "Git check out successful !!!"
'''
}catch(error) {
throw error
}
} else {
echo "checkout failed !!!"
}
}
}
}
stage('Package helm') {
steps {
script {
if ( env.PRODUCT_NAME == 'XL Release' ) {
try {
sh '''
echo Updating the helm dependencies for $PRODUCT_NAME
/usr/local/bin/helm dependency update xl-release-kubernetes-helm-chart
echo Packing the helm chart $PRODUCT_NAME
/usr/local/bin/helm package xl-release-kubernetes-helm-chart
echo Build package completed !!!
'''
}catch(error) {
throw error
}
} else {
try {
sh '''
echo Updating the helm dependencies for $PRODUCT_NAME
/usr/local/bin/helm dependency update xl-deploy-kubernetes-helm-chart-1
echo Packing the helm chart $PRODUCT_NAME
/usr/local/bin/helm package xl-deploy-kubernetes-helm-chart-1
echo Build package completed !!!
'''
}catch(error) {
throw error
}
}
}
}
}
stage('Push to nexus') {
steps {
script {
if ( env.PRODUCT_NAME == 'XL Release' && (env.PLATFORM_NAME == 'Onprem' | env.PLATFORM_NAME == 'EKS' )) {
try {
sh '''
echo Pushing the $PRODUCT_NAME build to nexus
curl -u ${NEXUS_USER}:${NEXUS_PASSWORD} ${NEXUS_URL_XLR} --upload-file *release*.tgz -v
echo Pushed $PRODUCT_NAME build successfull to nexus repository ${NEXUS_URL_XLR}
'''
}catch(error){
throw error
}
} else if ( env.PRODUCT_NAME == 'XL Deploy' && (env.PLATFORM_NAME == 'EKS' | env.PLATFORM_NAME == 'Onprem' )) {
try {
sh '''
echo Pushing the $PRODUCT_NAME build to nexus
curl -u ${NEXUS_USER}:${NEXUS_PASSWORD} ${NEXUS_URL_XLD} --upload-file *deploy*.tgz -v
echo Pushed $PRODUCT_NAME build successfull to nexus repository ${NEXUS_URL_XLD}
'''
}catch(error) {
throw error
}
} else if ( env.PRODUCT_NAME == 'XL Release' && (env.PLATFORM_NAME == 'Openshift_Onprem' | env.PLATFORM_NAME == 'Openshift_AWS' )) {
try {
sh '''
echo Pushing the $PRODUCT_NAME build to nexus
curl -u ${NEXUS_USER}:${NEXUS_PASSWORD} ${NEXUS_URL_OC_XLR} --upload-file *release*.tgz -v
echo Pushed $PRODUCT_NAME build successfull to nexus repository ${NEXUS_URL_OC_XLR}
'''
}catch(error) {
throw error
}
} else if ( env.PRODUCT_NAME == 'XL Deploy' && (env.PLATFORM_NAME == 'Openshift_Onprem' | env.PLATFORM_NAME == 'Openshift_AWS' )) {
try {
sh '''
echo Pushing the $PRODUCT_NAME build to nexus
curl -u ${NEXUS_USER}:${NEXUS_PASSWORD} ${NEXUS_URL_OC_XLD} --upload-file *deploy*.tgz -v
echo Pushed $PRODUCT_NAME build successfull to nexus repository ${NEXUS_URL_OC_XLD}
'''
}catch(error) {
throw error
}
} else {
echo "Push to nexus failed !!!"
}
}
}
}
stage('Push to Xebialabs dist') {
steps {
script {
echo "Pushing the build to Xebilabs dist"
}
}
}
stage('Deploy to Onprem') {
when {
anyOf {
expression { params.INSTALL_CHART == 'YES' && params.PRODUCT == 'XL Release' && params.PLATFORM == 'Onprem' }
expression { params.INSTALL_CHART == 'YES' && params.PRODUCT == 'XL Deploy' && params.PLATFORM == 'Onprem' }
}
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'ON_PREM_K8S', passwordVariable: 'PASSWORD', usernameVariable: 'USER_NAME')]) {
withKubeConfig(caCertificate: '', clusterName: 'kubernetes', contextName: 'kubernetes-admin@kubernetes', credentialsId: 'ON_PREM_K8S', namespace: 'default', serverUrl: 'https://172.16.16.21:6443') {
if ( env.PRODUCT_NAME == 'XL Release' && env.PLATFORM_NAME == 'Onprem' ) {
try {
echo "Installing $PRODUCT_NAME chart on $PLATFORM_NAME platform"
withCredentials([string(credentialsId: 'XLR_LIC', variable: 'XLR_LICENSE')]) {
withCredentials([string(credentialsId: 'XLR_KEYSTORE', variable: 'XLR_KEYSTORE')]) {
withCredentials([string(credentialsId: 'XLR_PASS_PHRASE', variable: 'XLR_PASS_PHRASE')]) {
sh '''
/usr/local/bin/helm install --generate-name *.tgz --set ingress.hosts[0]=$HOST_NAME_XLR_ONPREM --set xlrLicense=${XLR_LICENSE} --set RepositoryKeystore=${XLR_KEYSTORE} --set KeystorePassphrase=${XLR_PASS_PHRASE} --set Persistence.StorageClass=$STORAGE_CLASS_ONPREM
sleep 5
/usr/local/bin/kubectl get svc
echo "==================================================================="
echo "$PRODUCT_NAME deployed successfully on $PLATFORM_NAME platform !!!!"
echo "==================================================================="
'''
}
}
}
}catch(error) {
throw error
}
}else {
try {
echo "Installing $PRODUCT_NAME chart on $PLATFORM_NAME platform"
withCredentials([string(credentialsId: 'XLD_LIC', variable: 'XLD_LICENSE')]) {
withCredentials([string(credentialsId: 'XLD_KEYSTORE', variable: 'XLD_KEYSTORE')]) {
withCredentials([string(credentialsId: 'XLD_PASS_PHRASE', variable: 'XLD_PASS_PHRASE')]) {
sh '''
/usr/local/bin/helm install --generate-name *.tgz --set ingress.hosts[0]=$HOST_NAME_XLD_ONPREM --set xlrLicense=${XLD_LICENSE} --set RepositoryKeystore=${XLD_KEYSTORE} --set KeystorePassphrase=${XLD_PASS_PHRASE} --set Persistence.StorageClass=$STORAGE_CLASS_ONPREM
sleep 5
/usr/local/bin/kubectl get svc
echo "==================================================================="
echo "$PRODUCT_NAME deployed successfully on $PLATFORM_NAME platform !!!!"
echo "==================================================================="
'''
}
}
}
}catch(error) {
throw error
}
}
}
}
}
}
}
stage('Deploy to EKS') {
when {
anyOf {
expression { params.INSTALL_CHART == 'YES' && params.PRODUCT == 'XL Release' && params.PLATFORM == 'EKS' }
expression { params.INSTALL_CHART == 'YES' && params.PRODUCT == 'XL Deploy' && params.PLATFORM == 'EKS' }
}
}
steps {
script {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AWS_CRED', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
withKubeConfig(caCertificate: '', clusterName: 'eks-devops', contextName: '[email protected]', credentialsId: 'EKS_CONFIG', namespace: 'default', serverUrl: 'https://CC5E2351F79187EF9D05C18AA2FE52D7.gr7.eu-west-1.eks.amazonaws.com') {
if ( env.PRODUCT_NAME == 'XL Release' && env.PLATFORM_NAME == 'EKS' ) {
try {
echo "Installing $PRODUCT_NAME chart on $PLATFORM_NAME platform"
withCredentials([string(credentialsId: 'XLR_LIC', variable: 'XLR_LICENSE')]) {
withCredentials([string(credentialsId: 'XLR_KEYSTORE', variable: 'XLR_KEYSTORE')]) {
withCredentials([string(credentialsId: 'XLR_PASS_PHRASE', variable: 'XLR_PASS_PHRASE')]) {
sh '''
/usr/local/bin/helm install --generate-name *.tgz --set ingress.hosts[0]=$HOST_NAME_XLR_EKS --set haproxy-ingress.controller.service.type=${LOADBALANCER} --set xlrLicense=${XLR_LICENSE} --set RepositoryKeystore=${XLR_KEYSTORE} --set KeystorePassphrase=${XLR_PASS_PHRASE} --set Persistence.StorageClass=$STORAGE_CLASS_EKS
sleep 5
/usr/local/bin/kubectl get svc
echo "==================================================================="
echo "$PRODUCT_NAME deployed successfully on $PLATFORM_NAME platform !!!!"
echo "==================================================================="
'''
}
}
}
}catch(error) {
throw error
}
} else {
try {
echo "Installing $PRODUCT_NAME chart on $PLATFORM_NAME platform"
withCredentials([string(credentialsId: 'XLD_LIC', variable: 'XLD_LICENSE')]) {
withCredentials([string(credentialsId: 'XLD_KEYSTORE', variable: 'XLD_KEYSTORE')]) {
withCredentials([string(credentialsId: 'XLD_PASS_PHRASE', variable: 'XLD_PASS_PHRASE')]) {
sh '''
/usr/local/bin/helm install --generate-name *.tgz --set ingress.hosts[0]=$HOST_NAME_XLD_EKS --set haproxy-ingress.controller.service.type=${LOADBALANCER} --set xlrLicense=${XLD_LICENSE} --set RepositoryKeystore=${XLD_KEYSTORE} --set KeystorePassphrase=${XLD_PASS_PHRASE} --set Persistence.StorageClass=$STORAGE_CLASS_EKS
sleep 5
/usr/local/bin/kubectl get svc
echo "==================================================================="
echo "$PRODUCT_NAME deployed successfully on $PLATFORM_NAME platform !!!!"
echo "==================================================================="
'''
}
}
}
}catch(error){
throw error
}
}
}
}
}
}
}
stage('Deploy to AWS Openshift') {
when {
anyOf {
expression { params.INSTALL_CHART == 'YES' && params.PRODUCT == 'XL Release' && params.PLATFORM == 'Openshift_AWS' }
expression { params.INSTALL_CHART == 'YES' && params.PRODUCT == 'XL Deploy' && params.PLATFORM == 'Openshift_AWS' }
}
}
steps {
script {
if ( env.PRODUCT_NAME == 'XL Release' && env.PLATFORM_NAME == 'Openshift_AWS') {
try {
withCredentials([string(credentialsId: 'XLR_LIC', variable: 'XLR_LICENSE')]) {
withCredentials([string(credentialsId: 'XLR_KEYSTORE', variable: 'XLR_KEYSTORE')]) {
withCredentials([string(credentialsId: 'XLR_PASS_PHRASE', variable: 'XLR_PASS_PHRASE')]) {
sh '''
echo "Installing $PRODUCT_NAME on $PLATFORM_NAME platform"
/usr/local/bin/oc login --username=kubeadmin --password=$OPENSHIFT_AWS_CRED --server=$OPENSHIFT_AWS_SERVER_URL
/usr/local/bin/oc project pipeline
/usr/local/bin/helm install --generate-name *.tgz --set route.hosts[0]=$HOST_NAME_XLR_OPENSHIFT --set xlrLicense=${XLR_LICENSE} --set RepositoryKeystore=${XLR_KEYSTORE} --set KeystorePassphrase=${XLR_PASS_PHRASE} --set Persistence.StorageClass=$STORAGE_CLASS_EKS
echo "==================================================================="
echo "$PRODUCT_NAME deployed successfully on $PLATFORM_NAME platform !!!!"
echo "==================================================================="
'''
}
}
}
}catch(error){
throw error
}
}else {
try {
withCredentials([string(credentialsId: 'XLD_LIC', variable: 'XLD_LICENSE')]) {
withCredentials([string(credentialsId: 'XLD_KEYSTORE', variable: 'XLD_KEYSTORE')]) {
withCredentials([string(credentialsId: 'XLD_PASS_PHRASE', variable: 'XLD_PASS_PHRASE')]) {
sh '''
echo "Installing $PRODUCT_NAME on $PLATFORM_NAME platform"
/usr/local/bin/oc login --username=kubeadmin --password=$OPENSHIFT_AWS_CRED --server=$OPENSHIFT_AWS_SERVER_URL
/usr/local/bin/oc project pipeline
/usr/local/bin/helm install --generate-name *.tgz --set route.hosts[0]=$HOST_NAME_XLD_OPENSHIFT --set xlrLicense=${XLD_LICENSE} --set RepositoryKeystore=${XLD_KEYSTORE} --set KeystorePassphrase=${XLD_PASS_PHRASE} --set Persistence.StorageClass=$STORAGE_CLASS_EKS
echo "==================================================================="
echo "$PRODUCT_NAME deployed successfully on $PLATFORM_NAME platform !!!!"
echo "==================================================================="
'''
}
}
}
}catch(error){
throw error
}
}
}
}
}
}
post {
always {
cleanWs()
}
// success {
// mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "SUCCESS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
// }
// failure {
// mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
// }
}
}