-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
796 lines (689 loc) · 28.3 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import java.util.regex.Pattern
@NonCPS
String getUrlFromRoute(String routeName, String projectNameSpace = '') {
def nameSpaceFlag = ''
if(projectNameSpace?.trim()) {
nameSpaceFlag = "-n ${projectNameSpace}"
}
def url = sh (
script: "oc get routes ${nameSpaceFlag} -o wide --no-headers | awk \'/${routeName}/{ print match(\$0,/edge/) ? \"https://\"\$2 : \"http://\"\$2 }\'",
returnStdout: true
).trim()
return url
}
/*
* Sends a rocket chat notification
*/
def notifyRocketChat(text, url) {
def rocketChatURL = url
def message = text.replaceAll(~/\'/, "")
def payload = JsonOutput.toJson([
"username":"Jenkins",
"icon_url":"https://wiki.jenkins.io/download/attachments/2916393/headshot.png",
"text": message
])
sh("curl -X POST -H 'Content-Type: application/json' --data \'${payload}\' ${rocketChatURL}")
}
/*
* takes in a sonarqube status json payload
* and returns the status string
*/
def sonarGetStatus (jsonPayload) {
def jsonSlurper = new JsonSlurper()
return jsonSlurper.parseText(jsonPayload).projectStatus.status
}
/*
* takes in a sonarqube status json payload
* and returns the date string
*/
def sonarGetDate (jsonPayload) {
def jsonSlurper = new JsonSlurper()
return jsonSlurper.parseText(jsonPayload).projectStatus.periods[0].date
}
boolean imageTaggingComplete ( String sourceTag, String destinationTag, String action, def iterations = 6 ) {
def sourceImageName = sh returnStdout: true, script: "oc describe istag/lup-public-static:${sourceTag} | head -n 1".trim()
def destinationImageName = sh returnStdout: true, script: "oc describe istag/lup-public-static:${destinationTag} | head -n 1".trim()
int delay = 0
for (int i=0; i<iterations; i++){
echo "waiting to ${action}, iterator is: ${i}, the max iterator is: ${iterations} \n ${sourceTag}: ${sourceImageName} ${destinationTag}: ${destinationImageName}"
if(sourceImageName == destinationImageName){
echo "${action} complete"
return true
} else {
delay = (1<<i) // exponential backoff
sleep(delay)
destinationImageName = sh returnStdout: true, script: "oc describe istag/lup-public-static:${destinationTag} | head -n 1".trim()
}
}
return false
}
boolean sonarqubeReportComplete ( String oldDate, String sonarqubeStatusUrl, def iterations = 6 ) {
def oldSonarqubeReportDate = oldDate
def newSonarqubeReportDate = sonarGetDate ( sh ( returnStdout: true, script: "curl -w '%{http_code}' '${sonarqubeStatusUrl}'" ) )
int delay = 0
for (int i=0; i<iterations; i++) {
echo "waiting for sonarqube report, iterator is: ${i}, max iterator is: ${iterations} \n Old Date: ${oldSonarqubeReportDate} \n New Date: ${newSonarqubeReportDate}"
if (oldSonarqubeReportDate != newSonarqubeReportDate) {
echo "sonarqube report complete"
return true
} else {
delay = (1<<i) // exponential backoff
sleep(delay)
newSonarqubeReportDate = sonarGetDate ( sh ( returnStdout: true, script: "curl -w '%{http_code}' '${sonarqubeStatusUrl}'" ) )
}
}
return false
}
/*
* Updates the global pastBuilds array: it will iterate recursively
* and add all the builds prior to the current one that had a result
* different than 'SUCCESS'.
*/
def buildsSinceLastSuccess(previousBuild, build) {
if ((build != null) && (build.result != 'SUCCESS')) {
pastBuilds.add(build)
buildsSinceLastSuccess(pastBuilds, build.getPreviousBuild())
}
}
/*
* Generates a string containing all the commit messages from
* the builds in pastBuilds.
*/
@NonCPS
def getChangeLog(pastBuilds) {
def log = ""
for (int x = 0; x < pastBuilds.size(); x++) {
for (int i = 0; i < pastBuilds[x].changeSets.size(); i++) {
def entries = pastBuilds[x].changeSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
log += "* ${entry.msg} by ${entry.author} \n"
}
}
}
return log;
}
def nodejsTester () {
openshift.withCluster() {
openshift.withProject() {
podTemplate(
label: 'node-tester',
name: 'node-tester',
serviceAccount: 'jenkins',
cloud: 'openshift',
slaveConnectTimeout: 300,
containers: [
containerTemplate(
name: 'jnlp',
image: 'registry.access.redhat.com/openshift3/jenkins-agent-nodejs-8-rhel7',
resourceRequestCpu: '500m',
resourceLimitCpu: '800m',
resourceRequestMemory: '2Gi',
resourceLimitMemory: '4Gi',
workingDir: '/tmp',
command: '',
)
]) {
node("node-tester") {
checkout scm
try {
sh 'npm run tests'
} finally {
echo "Unit Tests Passed"
}
}
}
return true
}
}
}
def nodejsLinter () {
openshift.withCluster() {
openshift.withProject() {
podTemplate(
label: 'node-linter',
name: 'node-linter',
serviceAccount: 'jenkins',
cloud: 'openshift',
slaveConnectTimeout: 300,
containers: [
containerTemplate(
name: 'jnlp',
image: 'registry.access.redhat.com/openshift3/jenkins-agent-nodejs-8-rhel7',
resourceRequestCpu: '500m',
resourceLimitCpu: '800m',
resourceRequestMemory: '2Gi',
resourceLimitMemory: '4Gi',
activeDeadlineSeconds: '1200',
workingDir: '/tmp',
command: '',
args: '${computer.jnlpmac} ${computer.name}',
)
]) {
node("node-linter") {
checkout scm
try {
// install deps to get angular-cli
sh '''
npm install @angular/compiler @angular/core @angular/cli @angular-devkit/build-angular codelyzer rxjs tslint
npm run lint
'''
} finally {
echo "Linting Done"
}
}
}
return true
}
}
}
// todo templates can be pulled from a repository, instead of declared here
def nodejsSonarqube () {
openshift.withCluster() {
openshift.withProject() {
podTemplate(
label: 'node-sonarqube',
name: 'node-sonarqube',
serviceAccount: 'jenkins',
cloud: 'openshift',
slaveConnectTimeout: 300,
containers: [
containerTemplate(
name: 'jnlp',
image: 'registry.access.redhat.com/openshift3/jenkins-agent-nodejs-8-rhel7',
resourceRequestCpu: '500m',
resourceLimitCpu: '1000m',
resourceRequestMemory: '2Gi',
resourceLimitMemory: '4Gi',
workingDir: '/tmp',
command: '',
args: '${computer.jnlpmac} ${computer.name}',
)
]) {
node("node-sonarqube") {
checkout scm
dir('sonar-runner') {
try {
// get sonarqube url
def SONARQUBE_URL = getUrlFromRoute('sonarqube').trim()
echo "${SONARQUBE_URL}"
// sonarqube report link
def SONARQUBE_STATUS_URL = "${SONARQUBE_URL}/api/qualitygates/project_status?projectKey=lup-public"
// The name of your SonarQube project
def SONAR_PROJECT_NAME = 'lup-public'
// The project key of your SonarQube project
def SONAR_PROJECT_KEY = 'lup-public'
// The base directory of your project.
// This is relative to the location of the `sonar-runner` directory within your project.
// More accurately this is relative to the Gradle build script(s) that manage the SonarQube Scanning
def SONAR_PROJECT_BASE_DIR = '../'
// The source code directory you want to scan.
// This is relative to the project base directory.
def SONAR_SOURCES = './src/app'
boolean firstScan = false;
def OLD_SONAR_DATE
try {
// get old sonar report date
def OLD_SONAR_DATE_JSON = sh(returnStdout: true, script: "curl -w '%{http_code}' '${SONARQUBE_STATUS_URL}'")
OLD_SONAR_DATE = sonarGetDate (OLD_SONAR_DATE_JSON)
} catch (error) {
firstScan = true
}
// run scan
sh "npm install typescript@3.2.1"
sh "ls -la ../src"
sh returnStdout: true, script: "./gradlew sonarqube --stacktrace --info --debug \
-Dsonar.host.url=${SONARQUBE_URL} \
-Dsonar. \
-Dsonar.verbose=true \
-Dsonar.projectName='${SONAR_PROJECT_NAME}' \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.projectBaseDir=${SONAR_PROJECT_BASE_DIR} \
-Dsonar.sources='src/app'"
if ( !firstScan ) {
// wiat for report to be updated
if ( !sonarqubeReportComplete ( OLD_SONAR_DATE, SONARQUBE_STATUS_URL ) ) {
echo "sonarqube report failed to complete, or timed out"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n sonarqube report failed to complete, or timed out : ${SONARQUBE_URL}",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
}
} else {
sleep (30)
}
// check if sonarqube passed
//sh("oc extract secret/sonarqube-status-urls --to=${env.WORKSPACE}/sonar-runner --confirm")
SONARQUBE_STATUS_JSON = sh(returnStdout: true, script: "curl -w '%{http_code}' '${SONARQUBE_STATUS_URL}'")
SONARQUBE_STATUS = sonarGetStatus (SONARQUBE_STATUS_JSON)
if ( "${SONARQUBE_STATUS}" == "ERROR") {
echo "Scan Failed"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Sonarqube scan failed: : ${SONARQUBE_URL}",
ROCKET_DEPLOY_WEBHOOK
)
echo "Sonarqube Scan Failed"
currentBuild.result = 'FAILURE'
exit 1
} else {
echo "Sonarqube Scan Passed"
}
} catch (error) {
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n ${error.message}",
ROCKET_DEPLOY_WEBHOOK
)
throw error
} finally {
echo "Sonarqube Scan Complete"
}
}
}
}
return true
}
}
}
def zapScanner () {
openshift.withCluster() {
openshift.withProject() {
// The jenkins-slave-zap image has been purpose built for supporting ZAP scanning.
podTemplate(
label: 'owasp-zap',
name: 'owasp-zap',
serviceAccount: 'jenkins',
cloud: 'openshift',
slaveConnectTimeout: 300,
containers: [
containerTemplate(
name: 'jnlp',
image: '172.50.0.2:5000/openshift/jenkins-slave-zap',
resourceRequestCpu: '500m',
resourceLimitCpu: '1000m',
resourceRequestMemory: '3Gi',
resourceLimitMemory: '4Gi',
workingDir: '/home/jenkins',
command: '',
args: '${computer.jnlpmac} ${computer.name}'
)
]
){
node('owasp-zap') {
// The name of the ZAP report
def ZAP_REPORT_NAME = "zap-report.xml"
// The location of the ZAP reports
def ZAP_REPORT_PATH = "/zap/wrk/${ZAP_REPORT_NAME}"
// The name of the "stash" containing the ZAP report
def ZAP_REPORT_STASH = "zap-report"
// Dynamicaly determine the target URL for the ZAP scan ...
def TARGET_URL = getUrlFromRoute('lup-public-dev', 'xti26n-dev').trim()
echo "Target URL: ${TARGET_URL}"
dir('zap') {
try {
// The ZAP scripts are installed on the root of the jenkins-slave-zap image.
// When running ZAP from there the reports will be created in /zap/wrk/ by default.
// ZAP has problems with creating the reports directly in the Jenkins
// working directory, so they have to be copied over after the fact.
def retVal = sh (
returnStatus: true,
script: "/zap/zap-baseline.py -x ${ZAP_REPORT_NAME} -t ${TARGET_URL}"
)
echo "Return value is: ${retVal}"
// Copy the ZAP report into the Jenkins working directory so the Jenkins tools can access it.
sh (
returnStdout: true,
script: "mkdir -p ./wrk/ && cp /zap/wrk/${ZAP_REPORT_NAME} ./wrk/"
)
} catch (error) {
// revert dev from backup
echo "Reverting dev image form backup..."
openshiftTag destStream: 'lup-public-static', verbose: 'false', destTag: 'dev', srcStream: 'lup-public-static', srcTag: 'dev-backup'
// wait for revert to complete
if(!imageTaggingComplete ('dev-backup', 'dev', 'revert')) {
echo "Failed to revert dev image after Zap scan failed, please revert the dev image manually from dev-backup"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Zap scan failed: ${SONARQUBE_URL} \n Automatic revert of the deployment also failed, please revert the dev image manually from dev-backup",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
}
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Zap scan failed: ${SONARQUBE_URL} \n dev mage was reverted",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
}
}
// Stash the ZAP report for publishing in a different stage (which will run on a different pod).
echo "Stash the report for the publishing stage ..."
stash name: "${ZAP_REPORT_STASH}", includes: "zap/wrk/*.xml"
}
}
}
}
}
def postZapToSonar () {
openshift.withCluster() {
openshift.withProject() {
// The jenkins-python3nodejs template has been purpose built for supporting SonarQube scanning.
podTemplate(
label: 'zap-to-sonnar',
name: 'zap-to-sonnar',
serviceAccount: 'jenkins',
cloud: 'openshift',
slaveConnectTimeout: 300,
containers: [
containerTemplate(
name: 'jnlp',
image: 'registry.access.redhat.com/openshift3/jenkins-agent-nodejs-8-rhel7',
resourceRequestCpu: '500m',
resourceLimitCpu: '1000m',
resourceRequestMemory: '2Gi',
resourceLimitMemory: '4Gi',
workingDir: '/tmp',
command: '',
args: '${computer.jnlpmac} ${computer.name}',
)
]
){
node('zap-to-sonnar') {
// The name of the ZAP report
def ZAP_REPORT_NAME = "zap-report.xml"
// The location of the ZAP reports
def ZAP_REPORT_PATH = "/zap/wrk/${ZAP_REPORT_NAME}"
// The name of the "stash" containing the ZAP report
def ZAP_REPORT_STASH = "zap-report"
// get sonarqube url
def SONARQUBE_URL = getUrlFromRoute('sonarqube').trim()
// url for the sonarqube report
def SONARQUBE_STATUS_URL = "${SONARQUBE_URL}/api/qualitygates/project_status?projectKey=lup-public-zap-scan"
boolean firstScan = false
def OLD_ZAP_DATE
try {
// get old sonar report date
def OLD_ZAP_DATE_JSON = sh(returnStdout: true, script: "curl -w '%{http_code}' '${SONARQUBE_STATUS_URL}'")
OLD_ZAP_DATE = sonarGetDate (OLD_ZAP_DATE_JSON)
} catch (error) {
firstScan = true
}
echo "Checking out the sonar-runner folder ..."
checkout scm
echo "Preparing the report for the publishing ..."
unstash name: "${ZAP_REPORT_STASH}"
echo "Publishing the report ..."
dir('sonar-runner') {
sh "npm install typescript@3.2.1"
sh (
// 'sonar.zaproxy.reportPath' must be set to the absolute path of the xml formatted ZAP report.
// Exclude the report from being scanned as an xml file. We only care about the results of the ZAP scan.
returnStdout: true,
script: "./gradlew sonarqube --stacktrace --info \
-Dsonar.verbose=true \
-Dsonar.host.url=${SONARQUBE_URL} \
-Dsonar.projectName='lup-public-zap-scan'\
-Dsonar.projectKey='lup-public-zap-scan' \
-Dsonar.projectBaseDir='../' \
-Dsonar.sources=./src/app \
-Dsonar.zaproxy.reportPath=${WORKSPACE}${ZAP_REPORT_PATH} \
-Dsonar.exclusions=**/*.xml"
)
if ( !firstScan ) {
// wiat for report to be updated
if(!sonarqubeReportComplete ( OLD_ZAP_DATE, SONARQUBE_STATUS_URL)) {
echo "Zap report failed to complete, or timed out"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n sonarqube report failed to complete, or timed out : ${SONARQUBE_URL}",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
}
} else {
sleep(30)
}
// check if zap passed
ZAP_STATUS_JSON = sh(returnStdout: true, script: "curl -w '%{http_code}' '${SONARQUBE_STATUS_URL}'")
ZAP_STATUS = sonarGetStatus (ZAP_STATUS_JSON)
if ( "${ZAP_STATUS}" == "ERROR" ) {
echo "ZAP scan failed"
// revert dev from backup
echo "Reverting dev image form backup..."
openshiftTag destStream: 'lup-public-static', verbose: 'false', destTag: 'dev', srcStream: 'lup-public-static', srcTag: 'dev-backup'
// wait for revert to complete
if(!imageTaggingComplete ('dev-backup', 'dev', 'revert')) {
echo "Failed to revert dev image after Zap scan failed, please revert the dev image manually from dev-backup"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Zap scan failed: ${SONARQUBE_URL} \n Automatic revert of the deployment also failed, please revert the dev image manually from dev-backup",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
}
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n he latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Zap scan failed: ${SONARQUBE_URL} \n dev image has been reverted",
ROCKET_DEPLOY_WEBHOOK
)
echo "Zap scan Failed"
echo "Reverted dev deployment from backup"
currentBuild.result = 'FAILURE'
exit 1
} else {
echo "ZAP Scan Passed"
}
}
}
}
}
}
}
def CHANGELOG = "No new changes"
def IMAGE_HASH = "latest"
pipeline {
agent any
options {
disableResume()
}
stages {
stage('Parallel Build Steps') {
failFast true
parallel {
stage('Build') {
agent any
steps {
script {
pastBuilds = []
buildsSinceLastSuccess(pastBuilds, currentBuild);
CHANGELOG = getChangeLog(pastBuilds);
echo ">>>>>>Changelog: \n ${CHANGELOG}"
try {
sh("oc extract secret/rocket-chat-secrets --to=${env.WORKSPACE} --confirm")
ROCKET_DEPLOY_WEBHOOK = sh(returnStdout: true, script: 'cat rocket-deploy-webhook')
echo "Building landuseplanning-public develop branch"
openshiftBuild bldCfg: 'angular-builder', showBuildLogs: 'true'
openshiftBuild bldCfg: 'lup-public', showBuildLogs: 'true'
openshiftBuild bldCfg: 'lup-public-static', showBuildLogs: 'true'
echo "Build done"
echo ">>> Get Image Hash"
// Don't tag with BUILD_ID so the pruner can do it's job; it won't delete tagged images.
// Tag the images for deployment based on the image's hash
IMAGE_HASH = sh (
script: """oc get istag lup-public-static:latest -o template --template=\"{{.image.dockerImageReference}}\"|awk -F \":\" \'{print \$3}\'""",
returnStdout: true).trim()
echo ">> IMAGE_HASH: ${IMAGE_HASH}"
} catch (error) {
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The build ${env.BUILD_DISPLAY_NAME} of landuseplanning-public, seems to be broken.\n ${env.BUILD_URL}\n Error: \n ${error.message}",
ROCKET_DEPLOY_WEBHOOK
)
throw error
}
}
}
}
// stage('Unit Tests') {
// steps {
// script {
// echo "Running unit tests"
// def results = nodejsTester()
// }
// }
// }
stage('Linting') {
steps {
script {
echo "Running linter"
def results = nodejsLinter()
}
}
}
/*
stage('Sonarqube') {
steps {
script {
echo "Running Sonarqube"
def result = nodejsSonarqube()
}
}
} */
}
}
stage('Deploy to dev'){
steps {
script {
try {
// backup
echo "Backing up dev image..."
openshiftTag destStream: 'lup-public-static', verbose: 'false', destTag: 'dev-backup', srcStream: 'lup-public-static', srcTag: 'dev'
// wait for backup to complete
if( !imageTaggingComplete ('dev', 'dev-backup', 'backup')) {
echo "Dev image backup failed"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Dev image backup failed",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
}
// deploy
echo "Deploying to dev..."
openshiftTag destStream: 'lup-public-static', verbose: 'false', destTag: 'dev', srcStream: 'lup-public-static', srcTag: "${IMAGE_HASH}"
// wait for deployment to complete
if ( CHANGELOG && CHANGELOG != "No new changes" && !imageTaggingComplete ('latest', 'dev', 'deploy')) {
echo "Dev image deployment failed"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Dev image deployment failed",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
} else {
sleep (5)
}
openshiftVerifyDeployment depCfg: 'lup-public-dev', namespace: 'xti26n-dev', replicaCount: 1, verbose: 'false', verifyReplicaCount: 'false', waitTime: 600000
echo ">>>> Deployment Complete"
} catch (error) {
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The build ${env.BUILD_DISPLAY_NAME} of landuseplanning-public, seems to be broken.\n ${env.BUILD_URL}\n Error: ${error.message}",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
throw new Exception("Deploy failed")
}
}
}
}
stage('Zap') {
steps {
script {
echo "Running Zap Scan"
def result = zapScanner()
}
}
}
// stage('Zap to Sonarqube') {
// steps {
// script {
// echo "Posting Zap Scan to Sonarqube Report"
// def result = postZapToSonar()
// }
// }
// }
// stage('BDD Tests') {
// agent { label: bddPodLabel }
// steps{
// echo "checking out source"
// echo "Build: ${BUILD_ID}"
// checkout scm
// // todo determine how to call improved BDD Stack
// }
// }
stage('Deploy to test'){
steps {
script {
try {
notifyRocketChat(
"@all *[PUBLIC][DEV][INPUT]* \n A new version of landuseplanning-public is now in Dev, build: *${env.BUILD_DISPLAY_NAME}* \n Changes: \n ${CHANGELOG} \n\n _*Input is required to move this build to TEST*_\n${env.BUILD_URL}input",
ROCKET_DEPLOY_WEBHOOK
)
input "Deploy to test?"
} catch (error) {
echo "User has chosen to not deploy to test"
echo ">>>> Pipeline Complete"
currentBuild.result = 'SUCCESS'
return
}
try {
input "Deploy to test?"
// backup
echo "Backing up test image..."
openshiftTag destStream: 'lup-public-static', verbose: 'false', destTag: 'test-backup', srcStream: 'lup-public-static', srcTag: 'test'
// wait for backup to complete
if( !imageTaggingComplete ('test', 'test-backup', 'backup')) {
echo "Test image backup failed"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Test image backup failed",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
}
// deploy
echo "Deploying to test..."
openshiftTag destStream: 'lup-public-static', verbose: 'false', destTag: 'test', srcStream: 'lup-public-static', srcTag: "${IMAGE_HASH}"
// wait for deployment to complete
if ( !imageTaggingComplete ('latest', 'test', 'deploy')) {
echo "Test image deployment failed"
notifyRocketChat(
"@all *[PUBLIC][ERROR]* \n The latest build, ${env.BUILD_DISPLAY_NAME} of landuseplanning-public seems to be broken. \n ${env.BUILD_URL}\n Error: \n Test image deployment failed",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
exit 1
} else {
sleep (5)
}
openshiftVerifyDeployment depCfg: 'angular-on-nginx-test', namespace: 'xti26n-test', replicaCount: 1, verbose: 'false', verifyReplicaCount: 'false', waitTime: 600000
echo ">>>> Deployment Complete"
notifyRocketChat(
"*[PUBLIC][TEST]* \n A new version of landuseplanning-public is now in test, build: *${env.BUILD_DISPLAY_NAME}* \n Changes: \n ${CHANGELOG}",
ROCKET_DEPLOY_WEBHOOK
)
} catch (error) {
notifyRocketChat(
"@all The build ${env.BUILD_DISPLAY_NAME} of landuseplanning-public, seems to be broken.\n ${env.BUILD_URL}\n Error: ${error.message}",
ROCKET_DEPLOY_WEBHOOK
)
currentBuild.result = "FAILURE"
throw new Exception("Deploy failed")
}
}
}
}
}
}