-
Notifications
You must be signed in to change notification settings - Fork 124
/
Jenkinsfile
1504 lines (1411 loc) · 85 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
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@Library('shared-libraries') _
import groovy.json.JsonSlurper
import groovy.json.JsonSlurperClassic
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
JIRA_ID="";
commitMessage="";
def prResponse="";
def prNumber;
def props;
githubAPIUrl="https://api.github.com/repos/marklogic/marklogic-data-hub"
mlFFHost=""
cypressFFBaseUrl=""
fFsetupcomplete=false
fFtestcomplete=false
mlChHost=""
cypressChBaseUrl=""
chsetupcomplete=false
chtestcomplete=false
mlChMacHost=""
cypressChMacBaseUrl=""
chMacsetupcomplete=false
chMactestcomplete=false
def loadProperties() {
node {
checkout scm
properties = new Properties()
props.load(propertiesFile.newDataInputStream())
echo "Immediate one ${properties.repo}"
}
}
def dhflinuxTests(String mlVersion,String type){
script{
props = readProperties file:'data-hub/pipeline.properties';
copyRPM type,mlVersion
def dockerhost=setupMLDockerCluster 3
sh 'docker exec -u builder -i '+dockerhost+' /bin/sh -c "su -builder;export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;export M2_HOME=$MAVEN_HOME/bin;export PATH=$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH:$MAVEN_HOME/bin;cd $WORKSPACE/data-hub;rm -rf $GRADLE_USER_HOME/caches;./gradlew clean;set +e;./gradlew marklogic-data-hub:bootstrapAndTest -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew marklogic-data-hub-central:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/ |& tee console.log;sleep 10s;./gradlew ml-data-hub:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew installer-for-dhs:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew marklogic-data-hub-client-jar:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew ml-data-hub:testFullCycle -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;"'
junit '**/TEST-*.xml'
def output=readFile 'data-hub/console.log'
def result=false;
if(output.contains("npm ERR!")){
result=true;
}
if(result){
currentBuild.result='UNSTABLE'
}
}
}
def dhfCypressE2ETests(String mlVersion, String type){
script{
copyRPM type,mlVersion
env.mlVersion=mlVersion;
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
copyArtifacts filter: '**/*central*.war', fingerprintArtifacts: true, flatten: true, projectName: '${JOB_NAME}', selector: specific('${BUILD_NUMBER}')
sh(script:'''#!/bin/bash
export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;
export M2_HOME=$MAVEN_HOME/bin;
export PATH=$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH:$MAVEN_HOME/bin;
cd $WORKSPACE;
WAR_NAME=$(basename *central*.war )
cd $WORKSPACE/data-hub;
rm -rf $GRADLE_USER_HOME/caches;
./gradlew clean;
cd marklogic-data-hub-central/ui/e2e;
chmod +x setup.sh;
./setup.sh dhs=false mlHost=localhost;
nohup java -jar $WORKSPACE/$WAR_NAME >> nohup.out &
sleep 10s;
mkdir -p output;
docker build . -t cypresstest;
docker run --name cypresstest --env CYPRESS_BASE_URL=http://$HOSTNAME:8080 --env cypress_mlHost=$HOSTNAME cypresstest |& tee output/console.log;
docker cp cypresstest:results output;
docker cp cypresstest:cypress/videos output
mkdir -p ${mlVersion};
mv output ${mlVersion}/;
''')
junit '**/e2e/**/*.xml'
def output=readFile "data-hub/marklogic-data-hub-central/ui/e2e/${mlVersion}/output/console.log"
def result=false;
if(output.contains("npm ERR!")){
result=true;
}
if(result){
currentBuild.result='UNSTABLE'
}
}
}
def dhfWinTests(String mlVersion, String type){
script{
copyMSI type,mlVersion;
def pkgOutput=bat(returnStdout:true , script: '''
cd xdmp/src
for /f "delims=" %%a in ('dir /s /b *.msi') do set "name=%%~a"
echo %name%
''').trim().split();
def pkgLoc=pkgOutput[pkgOutput.size()-1]
gitCheckout 'ml-builds','https://github.com/marklogic/MarkLogic-Builds','master'
def bldOutput=bat(returnStdout:true , script: '''
cd ml-builds/scripts/lib/
CD
''').trim().split();
def bldPath=bldOutput[bldOutput.size()-1]
setupMLWinCluster bldPath,pkgLoc
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat clean'
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat marklogic-data-hub:bootstrapAndTest || exit /b 0'
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat marklogic-data-hub-central:test || exit /b 0'
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat ml-data-hub:test || exit /b 0'
junit '**/TEST-*.xml'
}
}
def winParallel(){
script{
copyMSI "Release","11.0.2";
def pkgOutput=bat(returnStdout:true , script: '''
cd xdmp/src
for /f "delims=" %%a in ('dir /s /b *.msi') do set "name=%%~a"
echo %name%
''').trim().split();
def pkgLoc=pkgOutput[pkgOutput.size()-1]
gitCheckout 'ml-builds','https://github.com/marklogic/MarkLogic-Builds','master'
def bldOutput=bat(returnStdout:true , script: '''
cd ml-builds/scripts/lib/
CD
''').trim().split();
def bldPath=bldOutput[bldOutput.size()-1]
setupMLWinCluster bldPath,pkgLoc,"w2k16-10-dhf-2,w2k16-10-dhf-3"
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat clean'
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat marklogic-data-hub:bootstrapAndTest || exit /b 0'
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat marklogic-data-hub-central:test || exit /b 0'
bat 'set PATH=C:\\Program Files\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd data-hub & gradlew.bat ml-data-hub:test || exit /b 0'
junit '**/TEST-*.xml'
}
}
def getReviewState(){
def reviewResponse;
def commitHash;
withCredentials([usernameColonPassword(credentialsId: '550650ab-ee92-4d31-a3f4-91a11d5388a3', variable: 'Credentials')]) {
reviewResponse = sh (returnStdout: true, script:'''
curl -u $Credentials -X GET '''+githubAPIUrl+'''/pulls/$CHANGE_ID/reviews
''')
commitHash = sh (returnStdout: true, script:'''
curl -u $Credentials -X GET '''+githubAPIUrl+'''/pulls/$CHANGE_ID
''')
}
def jsonObj = new JsonSlurperClassic().parseText(commitHash.toString().trim())
def commit_id=jsonObj.head.sha
println(commit_id)
def reviewState=getReviewStateOfPR reviewResponse,2,commit_id ;
return reviewState
}
def PRDraftCheck(){
withCredentials([usernameColonPassword(credentialsId: '550650ab-ee92-4d31-a3f4-91a11d5388a3', variable: 'Credentials')]) {
PrObj= sh (returnStdout: true, script:'''
curl -u $Credentials -X GET '''+githubAPIUrl+'''/pulls/$CHANGE_ID
''')
}
def jsonObj = new JsonSlurperClassic().parseText(PrObj.toString().trim())
return jsonObj.draft
}
def isPRUITest(){
withCredentials([usernameColonPassword(credentialsId: '550650ab-ee92-4d31-a3f4-91a11d5388a3', variable: 'Credentials')]) {
PrObj= sh (returnStdout: true, script:'''
curl -u $Credentials -X GET '''+githubAPIUrl+'''/pulls/$CHANGE_ID
''')
}
def jsonObj = new JsonSlurperClassic().parseText(PrObj.toString().trim())
for (label in jsonObj.labels){
if(label.name=="DO_NOT_RUN_UI_TESTS"){
return true
}
}
return false
}
void runCypressE2e(String cmd){
copyRPM 'Release','10.0-10'
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
sh 'rm -rf *central*.rpm || true'
copyArtifacts filter: '**/*.rpm', fingerprintArtifacts: true, flatten: true, projectName: '${JOB_NAME}', selector: specific('${BUILD_NUMBER}')
sh(script:'''#!/bin/bash
export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;
sudo mladmin stop-hubcentral
sudo mladmin install-hubcentral $WORKSPACE/*central*.rpm;
sudo mladmin add-javahome-hubcentral $JAVA_HOME
sudo mladmin start-hubcentral
''')
sh(script:'''#!/bin/bash
export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;
export M2_LOCAL_REPO=$WORKSPACE/$M2_HOME_REPO
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;
export PATH=$M2_LOCAL_REPO:$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH;
rm -rf $M2_LOCAL_REPO || true
mkdir -p $M2_LOCAL_REPO
cd $WORKSPACE/data-hub;
./gradlew publishToMavenLocal -Dmaven.repo.local=$M2_LOCAL_REPO -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/
'''
)
sh(script:'''
#!/bin/bash
export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;
export M2_LOCAL_REPO=$WORKSPACE/$M2_HOME_REPO
export PATH=$M2_LOCAL_REPO:$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH;
cd $WORKSPACE/data-hub;
rm -rf $GRADLE_USER_HOME/caches;
cd marklogic-data-hub-central/ui/e2e;
repo="maven {url '"$M2_LOCAL_REPO"'}"
sed -i "/repositories {/a$repo" hc-qa-project/build.gradle
chmod +x setup.sh;
./setup.sh dhs=false mlHost=localhost mlSecurityUsername=admin mlSecurityPassword=admin;
'''
)
sh(script:'''#!/bin/bash
export NODE_HOME=$NODE_HOME_DIR/bin;
export PATH=$NODE_HOME:$PATH
cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e
'''+cmd+''' |& tee -a e2e_err.log;
'''
)
junit '**/e2e/**/*.xml'
def output=readFile 'data-hub/marklogic-data-hub-central/ui/e2e/e2e_err.log'
if(output.contains("npm ERR!")){
// println("WARNING: cypress test run has errors in its log. Tests might run succesfully or with some failures.")
error "${STAGE_NAME} stage run with errors. Tests results can be all success or with some failures."
}
}
void UnitTest(){
props = readProperties file:'data-hub/pipeline.properties';
copyRPM 'Release','10.0-10'
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
sh 'export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;export M2_HOME=$MAVEN_HOME/bin;export PATH=$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH:$MAVEN_HOME/bin;cd $WORKSPACE/data-hub;rm -rf $GRADLE_USER_HOME/caches;./gradlew clean;./gradlew marklogic-data-hub:bootstrap -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew marklogic-data-hub-central:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew ml-data-hub:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew installer-for-dhs:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew marklogic-data-hub-client-jar:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/'
junit '**/TEST-*.xml'
jacoco classPattern: 'data-hub/marklogic-data-hub-central/build/classes/java/main/com/marklogic/hub/central,data-hub/marklogic-data-hub/build/classes/java/main/com/marklogic/hub',exclusionPattern: '**/*Test*.class'
if(env.CHANGE_TITLE){
JIRA_ID=env.CHANGE_TITLE.split(':')[0]
jiraAddComment comment: 'Jenkins Unit Test Results For PR Available', failOnError: false, idOrKey: JIRA_ID, site: 'JIRA'
}
if(!env.CHANGE_URL){
env.CHANGE_URL=" "
}
}
void PreBuildCheck() {
if(env.CHANGE_ID){
if(PRDraftCheck()){ sh 'exit 1' }
if((!env.CHANGE_TITLE.startsWith("DHFPROD-")) && (!env.CHANGE_TITLE.startsWith("DEVO-"))){ sh 'exit 1' }
if(getReviewState().equalsIgnoreCase("CHANGES_REQUESTED")){
println(reviewState)
sh 'exit 1'
}
if(!isChangeInUI() && isPRUITest()){env.NO_UI_TESTS=true}
}
def obj=new abortPrevBuilds();
obj.abortPrevBuilds();
}
void Tests(){
cleanWs deleteDirs: true, patterns: [[pattern: 'data-hub/**', type: 'EXCLUDE']]
props = readProperties file:'data-hub/pipeline.properties';
copyRPM 'Release','10.0-10'
def mlHubHosts=setupMLDockerNodes 3
sh 'export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;export M2_HOME=$MAVEN_HOME/bin;export PATH=$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH:$MAVEN_HOME/bin;cd $WORKSPACE/data-hub;rm -rf $GRADLE_USER_HOME/caches;./gradlew clean;./gradlew marklogic-data-hub:testAcceptance -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/ -PmlHost='+mlHubHosts
junit '**/TEST-*.xml'
if(env.CHANGE_TITLE){
JIRA_ID=env.CHANGE_TITLE.split(':')[0]
jiraAddComment comment: 'Jenkins Core Unit Test Results For PR Available', failOnError: false, idOrKey: JIRA_ID, site: 'JIRA'
}
if(!env.CHANGE_URL){
env.CHANGE_URL=" "
}
}
void RTLTests(String type,String mlVersion){
cleanWs deleteDirs: true, patterns: [[pattern: 'data-hub/**', type: 'EXCLUDE']]
props = readProperties file:'data-hub/pipeline.properties';
copyRPM type,mlVersion
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
sh '''
export PATH=$JAVA_HOME/bin:$PATH
cd $WORKSPACE/data-hub
./gradlew -g ./cache-build --continue clean marklogic-data-hub:bootstrap :marklogic-data-hub-central:testUI |& tee console.log
'''
junit '**/TEST-*.xml'
cobertura coberturaReportFile: '**/cobertura-coverage.xml'
def output=readFile 'data-hub/console.log'
if(output.contains("npm ERR!")){
error "${STAGE_NAME} tests failed but failures possibly was not reported with junit report. Please look at console to find failures"
}
if(env.CHANGE_TITLE){
JIRA_ID=env.CHANGE_TITLE.split(':')[0]
jiraAddComment comment: 'Jenkins Core Unit Test Results For PR Available', failOnError: false, idOrKey: JIRA_ID, site: 'JIRA'
}
if(!env.CHANGE_URL){
env.CHANGE_URL=" "
}
}
void BuildDatahub(){
script{
props = readProperties file:'data-hub/pipeline.properties';
if(env.CHANGE_TITLE){
JIRA_ID=env.CHANGE_TITLE.split(':')[0];
def transitionInput =[transition: [id: '41']]
//jiraTransitionIssue idOrKey: JIRA_ID, input: transitionInput, site: 'JIRA'
}
}
println(BRANCH_NAME)
sh 'export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;export M2_HOME=$MAVEN_HOME/bin;export PATH=$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH:$MAVEN_HOME/bin;cd $WORKSPACE/data-hub;rm -rf $GRADLE_USER_HOME/caches;./gradlew clean;./gradlew build -x test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/ --parallel;'
archiveArtifacts artifacts: 'data-hub/marklogic-data-hub/build/libs/* , data-hub/ml-data-hub-plugin/build/libs/* , data-hub/marklogic-data-hub-central/build/libs/* , data-hub/marklogic-data-hub-central/build/**/*.rpm , data-hub/installer-for-dhs/build/libs/marklogic* , data-hub/marklogic-data-hub-client-jar/build/libs/*client.jar ', onlyIfSuccessful: true
}
void dh5Example() {
sh 'cd $WORKSPACE/data-hub/examples/dh-5-example;repo="maven {";url="url \'https://nexus.marklogic.com/repository/maven-snapshots/\'";protocal="allowInsecureProtocol = true}";cred="credentials {";uname="username mavenUser";pass="password mavenPassword }";sed -i "/repositories {/a$protocal" build.gradle;sed -i "/repositories {/a$url" build.gradle;sed -i "/repositories {/a$pass" build.gradle;sed -i "/repositories {/a$uname" build.gradle;sed -i "/repositories {/a$cred" build.gradle;sed -i "/repositories {/a$repo" build.gradle;mkdir -p $WORKSPACE$GRADLE_DIR;cp ~/.gradle/gradle.properties $WORKSPACE$GRADLE_DIR;'
copyRPM 'Release','10.0-10'
script{
props = readProperties file:'data-hub/pipeline.properties';
def dockerhost=setupMLDockerCluster 3
sh '''
docker exec -u builder -i '''+dockerhost+''' /bin/sh -c "su -builder;export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;\
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR; \
export M2_HOME=$MAVEN_HOME/bin; \
export PATH=$JAVA_HOME/bin:$WORKSPACE$GRADLE_DIR:$PATH:$MAVEN_HOME/bin; \
cd $WORKSPACE/data-hub/examples/dh-5-example; \
rm -rf $WORKSPACE$GRADLE_DIR/caches; \
./gradlew -i hubInit -Ptesting=true; \
cp ../../marklogic-data-hub/gradle.properties .; \
./gradlew mlSetTraceEvents -Pevents=hub-core
./gradlew -i mlDeploy -Ptesting=true -PmlUsername=admin -PmlPassword=admin; \
./gradlew hubRunFlow -PflowName=ingestion_only-flow -Ptesting=true; \
./gradlew hubRunFlow -PflowName=ingestion_mapping-flow -Ptesting=true; \
./gradlew hubRunFlow -PflowName=ingestion_mapping_mastering-flow -Ptesting=true;
"
'''
}
}
void dhCustomHook() {
sh 'cd $WORKSPACE/data-hub/examples/dhf5-custom-hook;repo="maven {";url="url \'https://nexus.marklogic.com/repository/maven-snapshots/\'";protocal="allowInsecureProtocol = true}";cred="credentials {";uname="username mavenUser";pass="password mavenPassword }";sed -i "/repositories {/a$protocal" build.gradle;sed -i "/repositories {/a$url" build.gradle;sed -i "/repositories {/a$pass" build.gradle;sed -i "/repositories {/a$uname" build.gradle;sed -i "/repositories {/a$cred" build.gradle;sed -i "/repositories {/a$repo" build.gradle;mkdir -p $WORKSPACE$GRADLE_DIR;cp ~/.gradle/gradle.properties $WORKSPACE$GRADLE_DIR;'
copyRPM 'Release','10.0-10'
script{
props = readProperties file:'data-hub/pipeline.properties';
def dockerhost=setupMLDockerCluster 3
sh '''
docker exec -u builder -i '''+dockerhost+''' /bin/sh -c "su -builder;export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;\
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR; \
export M2_HOME=$MAVEN_HOME/bin; \
export PATH=$JAVA_HOME/bin:$WORKSPACE$GRADLE_DIR:$PATH:$MAVEN_HOME/bin; \
cd $WORKSPACE/data-hub/examples/dhf5-custom-hook; \
rm -rf $WORKSPACE$GRADLE_DIR/caches; \
./gradlew -i hubInit -Ptesting=true; \
cp ../../marklogic-data-hub/gradle.properties .; \
./gradlew -i mlDeploy -Ptesting=true -PmlUsername=admin -PmlPassword=admin; \
./gradlew hubRunFlow -PflowName=LoadOrders -Ptesting=true; \
./gradlew hubRunFlow -PflowName=LoadOrders -Ptesting=true;
"
'''
}
}
void mappingExample() {
sh 'cd $WORKSPACE/data-hub/examples/mapping-example;repo="maven {";url="url \'https://nexus.marklogic.com/repository/maven-snapshots/\'";protocal="allowInsecureProtocol = true}";cred="credentials {";uname="username mavenUser";pass="password mavenPassword }";sed -i "/repositories {/a$protocal" build.gradle;sed -i "/repositories {/a$url" build.gradle;sed -i "/repositories {/a$pass" build.gradle;sed -i "/repositories {/a$uname" build.gradle;sed -i "/repositories {/a$cred" build.gradle;sed -i "/repositories {/a$repo" build.gradle;mkdir -p $WORKSPACE$GRADLE_DIR;cp ~/.gradle/gradle.properties $WORKSPACE$GRADLE_DIR;'
copyRPM 'Release','10.0-10'
script{
props = readProperties file:'data-hub/pipeline.properties';
def dockerhost=setupMLDockerCluster 3
sh '''
docker exec -u builder -i '''+dockerhost+''' /bin/sh -c "su -builder;export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;\
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR; \
export M2_HOME=$MAVEN_HOME/bin; \
export PATH=$JAVA_HOME/bin:$WORKSPACE$GRADLE_DIR:$PATH:$MAVEN_HOME/bin; \
cd $WORKSPACE/data-hub/examples/mapping-example; \
rm -rf $WORKSPACE$GRADLE_DIR/caches; \
./gradlew -i hubInit -Ptesting=true; \
cp ../../marklogic-data-hub/gradle.properties .; \
./gradlew -i mlDeploy -Ptesting=true -PmlUsername=admin -PmlPassword=admin; \
./gradlew hubRunFlow -PflowName=jsonToJson -Ptesting=true; \
./gradlew hubRunFlow -PflowName=jsonToXml -Ptesting=true; \
./gradlew hubRunFlow -PflowName=xmlToJson -Ptesting=true; \
./gradlew hubRunFlow -PflowName=xmlToXml -Ptesting=true;
"
'''
}
}
void smartMastering() {
sh 'cd $WORKSPACE/data-hub/examples/smart-mastering-complete;repo="maven {";url="url \'https://nexus.marklogic.com/repository/maven-snapshots/\'";protocal="allowInsecureProtocol = true}";cred="credentials {";uname="username mavenUser";pass="password mavenPassword }";sed -i "/repositories {/a$protocal" build.gradle;sed -i "/repositories {/a$url" build.gradle;sed -i "/repositories {/a$pass" build.gradle;sed -i "/repositories {/a$uname" build.gradle;sed -i "/repositories {/a$cred" build.gradle;sed -i "/repositories {/a$repo" build.gradle;mkdir -p $WORKSPACE$GRADLE_DIR;cp ~/.gradle/gradle.properties $WORKSPACE$GRADLE_DIR;'
copyRPM 'Release','10.0-10'
script{
props = readProperties file:'data-hub/pipeline.properties';
def dockerhost=setupMLDockerCluster 3
sh '''
docker exec -u builder -i '''+dockerhost+''' /bin/sh -c "su -builder;export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;\
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR; \
export M2_HOME=$MAVEN_HOME/bin; \
export PATH=$JAVA_HOME/bin:$WORKSPACE$GRADLE_DIR:$PATH:$MAVEN_HOME/bin; \
cd $WORKSPACE/data-hub/examples/smart-mastering-complete; \
rm -rf $WORKSPACE$GRADLE_DIR/caches; \
./gradlew -i hubInit -Ptesting=true; \
cp ../../marklogic-data-hub/gradle.properties .; \
./gradlew -i mlDeploy -Ptesting=true -PmlUsername=admin -PmlPassword=admin; \
./gradlew hubRunFlow -PflowName=persons -Ptesting=true;
"
'''
}
}
void codeReview(){
def count=0;
retry(4){
count++;
props = readProperties file:'data-hub/pipeline.properties';
def reviewState=getReviewState()
if(env.CHANGE_TITLE.split(':')[1].contains("Automated PR")){
println("Automated PR")
sh 'exit 0'
}
else if(reviewState.equalsIgnoreCase("APPROVED")){
sh 'exit 0'
}
else if(reviewState.equalsIgnoreCase("CHANGES_REQUESTED")){
println("Changes Requested")
def author=env.CHANGE_AUTHOR.toString().trim().toLowerCase()
email=getEmailFromGITUser author;
if(count==4){
sendMail email,'<h3>Changes Requested for <a href=${CHANGE_URL}>PR</a>. Please resolve those Changes</h3><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>',false,'Changes Requested for $BRANCH_NAME '
}
currentBuild.result = 'ABORTED'
}
else{
withCredentials([usernameColonPassword(credentialsId: '550650ab-ee92-4d31-a3f4-91a11d5388a3', variable: 'Credentials')]) {
def reviewersList = sh (returnStdout: true, script:'''
curl -u $Credentials -X GET '''+githubAPIUrl+'''/pulls/$CHANGE_ID/requested_reviewers
''')
def reviewesList = sh (returnStdout: true, script:'''
curl -u $Credentials -X GET '''+githubAPIUrl+'''/pulls/$CHANGE_ID/reviews
''')
def slurper = new JsonSlurperClassic().parseText(reviewersList.toString().trim())
def emailList="";
if(slurper.users.isEmpty() && reviewesList.isEmpty()){
def author=env.CHANGE_AUTHOR.toString().trim().toLowerCase()
email=getEmailFromGITUser author;
if(count==4){
sendMail email,'<h3>Please assign some code reviewers <a href=${CHANGE_URL}>PR</a>. and restart this stage to continue.</h3><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>',false,'No Code reviewers assigned for $BRANCH_NAME '
}
sh 'exit 123'
}else{
for(def user:slurper.users){
email=getEmailFromGITUser user.login;
emailList+=email+',';
}
sendMail emailList,'<h3>Code Review Pending on <a href=${CHANGE_URL}>PR</a>.</h3><h3>Please click on proceed button from the pipeline view below if all the reviewers approved the code </h3><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>',false,'Code Review Pending on $BRANCH_NAME '
try{
timeout(time: 15, unit: 'MINUTES') {
input message:'Code-Review Done?'
}
}catch(FlowInterruptedException err){
user = err.getCauses()[0].getUser().toString();
println(user)
if(user.equalsIgnoreCase("SYSTEM")){
echo "Timeout 15mins"
sh 'exit 123'
}else{
currentBuild.result = 'ABORTED'
}
}
def author=env.CHANGE_AUTHOR.toString().trim().toLowerCase()
email=getEmailFromGITUser author;
if(count==4){
sendMail email,'<h3>Code Review is incomplete on <a href=${CHANGE_URL}>PR</a>.</h3><h3>Please Restart this stage from the pipeline view once code review is completed. </h3><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>',false,'Code Review is incomplete on $BRANCH_NAME '
}
}
}
}
}
}
void cypressE2EOnPremLinuxTests(String type,String mlVersion){
copyRPM type,mlVersion
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
copyArtifacts filter: '**/*central*.war', fingerprintArtifacts: true, flatten: true, projectName: '${JOB_NAME}', selector: specific('${BUILD_NUMBER}')
sh '''
sudo mladmin stop-hubcentral
cd $WORKSPACE
WAR_NAME=$(basename *central*.war )
nohup java -jar $WORKSPACE/$WAR_NAME &
'''
//wait for prem to start
timeout(10) {waitUntil initialRecurrencePeriod: 15000, { sh(script: 'ps aux | grep ".central.*\\.war" | grep -v grep | grep -v timeout', returnStatus: true) == 0 }}
sh '''
export NODE_HOME=$NODE_HOME_DIR/bin;
export PATH=$NODE_HOME:$JAVA_HOME/bin:$PATH
cd $WORKSPACE/data-hub
./gradlew -g ./cache-build clean publishToMavenLocal -Dmaven.repo.local=$M2_LOCAL_REPO
cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e
sed -i "s#gradlew #gradlew -Dmaven.repo.local=$M2_LOCAL_REPO -g ./cache-build #g" setup.sh
./setup.sh dhs=false mlHost=$HOSTNAME mlSecurityUsername=admin mlSecurityPassword=admin
npm run cy:run 2>&1 |& tee -a e2e_err.log
'''
junit '**/e2e/**/*.xml'
}
/*void cypressE2EOnPremMacTests(String type,String mlVersion){
copyDMG type,mlVersion
setUpMLMac '$WORKSPACE/xdmp/src/Mark*.dmg'
copyArtifacts filter: '**//*central*.war', fingerprintArtifacts: true, flatten: true, projectName: '${JOB_NAME}', selector: specific('${BUILD_NUMBER}')
sh '''
cd $WORKSPACE
WAR_NAME=$(basename *central*.war )
nohup java -jar $WORKSPACE/$WAR_NAME &
'''
//wait for prem to start
timeout(10) {waitUntil initialRecurrencePeriod: 15000, { sh(script: 'ps aux | grep ".central.*\\.war" | grep -v grep | grep -v timeout', returnStatus: true) == 0 }}
sh '''
export PATH=/usr/local/bin/:$JAVA_HOME/bin:$PATH
cd $WORKSPACE/data-hub
./gradlew -g ./cache-build clean publishToMavenLocal -Dmaven.repo.local=$M2_LOCAL_REPO
cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e
sed -i '.bak' "s#gradlew #gradlew -Dmaven.repo.local=$M2_LOCAL_REPO -g ./cache-build #g" setup.sh
./setup.sh dhs=false mlHost=$HOSTNAME mlSecurityUsername=admin mlSecurityPassword=admin
npm run cy:run-chrome 2>&1 | tee -a e2e_err.log
'''
junit '**//*e2e/**//*.xml'
}*/
void cypressE2EOnPremWinTests(String type,String mlVersion){
copyMSI type,mlVersion;
def pkgOutput=bat(returnStdout:true , script: '''
cd xdmp/src
for /f "delims=" %%a in ('dir /s /b *.msi') do set "name=%%~a"
echo %name%
''').trim().split();
def pkgLoc=pkgOutput[pkgOutput.size()-1]
gitCheckout 'ml-builds','https://github.com/marklogic/MarkLogic-Builds','master'
def bldOutput=bat(returnStdout:true , script: '''
cd ml-builds/scripts/lib/
CD
''').trim().split();
def bldPath=bldOutput[bldOutput.size()-1]
setupMLWinCluster bldPath,pkgLoc
copyArtifacts filter: '**/*central*.war', fingerprintArtifacts: true, flatten: true, projectName: '${JOB_NAME}', selector: specific('${BUILD_NUMBER}')
bat '''
for /f "delims=" %%a in ('dir /s /b *.war') do set "name=%%~a"
start java -jar %name%
'''
//wait for prem to start
timeout(10) {waitUntil initialRecurrencePeriod: 15000, { bat(script: 'jps | grep war', returnStatus: true) == 0 }}
bat "set PATH=C:\\Program Files (x86)\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd $WORKSPACE/data-hub & gradlew.bat -g ./cache-build clean publishToMavenLocal -Dmaven.repo.local=$M2_LOCAL_REPO"
bat "set PATH=C:\\Program Files (x86)\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e &sed -i 's#gradlew #gradlew -Dmaven.repo.local=$M2_LOCAL_REPO -g ./cache-build #g' setup.sh &sh setup.sh dhs=false mlHost=%COMPUTERNAME% mlSecurityUsername=admin mlSecurityPassword=admin"
bat "set PATH=C:\\Program Files (x86)\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH & cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e & npm run cy:run 2>&1 | tee -a e2e_err.log"
junit '**/e2e/**/*.xml'
}
void cypressE2EOnPremWinChromeTests(){
sleep time: 12, unit: 'MINUTES'
waitUntil(initialRecurrencePeriod: 120000) {
return chsetupcomplete
}
env.cypressChBaseUrl=cypressChBaseUrl.trim()
env.mlChHost=mlChHost.trim()
bat script: """
setlocal
set ERRORLEVEL=0
set PATH=C:\\Program Files (x86)\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH
set CYPRESS_BASE_URL=${cypressChBaseUrl}
set mlHost=${mlChHost}
cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e
npm run cy:run-chrome-headed -- --config baseUrl=${cypressChBaseUrl} --env mlHost=${mlChHost} >> e2e_err.log
"""
findText(textFinders: [textFinder('npm error')])
junit '**/e2e/**/*.xml'
}
void mergePR(){
withCredentials([usernameColonPassword(credentialsId: '550650ab-ee92-4d31-a3f4-91a11d5388a3', variable: 'Credentials')]) {
script{
props = readProperties file:'data-hub/pipeline.properties';
JIRA_ID=env.CHANGE_TITLE.split(':')[0]
def response = sh (returnStdout: true, script:'''curl -u $Credentials --header "application/vnd.github.merge-info-preview+json" "'''+githubAPIUrl+'''/pulls/$CHANGE_ID" | grep '"mergeable_state":' | cut -d ':' -f2 | cut -d ',' -f1 | tr -d '"' ''')
response=response.trim();
println(response)
if(response.equals("clean")){
println("merging can be done")
sh "curl -o - -s -w \"\n%{http_code}\n\" -X PUT -d '{\"commit_title\": \"$JIRA_ID: merging PR\", \"merge_method\": \"rebase\"}' -u $Credentials "+ githubAPIUrl+"/pulls/$CHANGE_ID/merge | tail -2 > mergeResult.txt"
def mergeResult = readFile('mergeResult.txt').trim()
if(mergeResult=="200"){
println("Merge successful")
}else{
println("Merge Failed")
sh 'exit 123'
}
}else if(response.equals("blocked")){
println("retry blocked");
withCredentials([usernameColonPassword(credentialsId: '550650ab-ee92-4d31-a3f4-91a11d5388a3', variable: 'Credentials')]) {
def reviewersList = sh (returnStdout: true, script:'''
curl -u $Credentials -X GET '''+githubAPIUrl+'''/pulls/$CHANGE_ID/requested_reviewers
''')
def slurper = new JsonSlurperClassic().parseText(reviewersList.toString().trim())
def emailList="";
for(def user:slurper.users){
email=getEmailFromGITUser user.login;
emailList+=email+',';
}
sendMail emailList,'Check the Pipeline View Here: ${JENKINS_URL}/blue/organizations/jenkins/Datahub_CI/detail/$JOB_BASE_NAME/$BUILD_ID \n\n\n Check Console Output Here: ${BUILD_URL}/console \n\n\n $BRANCH_NAME is waiting for the code-review to complete. Please click on proceed button if all the reviewers approved the code here. \n\n ${BUILD_URL}input ',false,'Waiting for code review $BRANCH_NAME '
}
sleep time: 30, unit: 'MINUTES'
throw new Exception("Waiting for all the status checks to pass");
}else if(response.equals("unstable")){
println("retry unstable")
sh "curl -o - -s -w \"\n%{http_code}\n\" -X PUT -d '{\"commit_title\": \"$JIRA_ID: merging PR\", \"merge_method\": \"rebase\"}' -u $Credentials "+githubAPIUrl+"/pulls/$CHANGE_ID/merge | tail -2 > mergeResult.txt"
def mergeResult = readFile('mergeResult.txt').trim()
if(mergeResult=="200"){
println("Merge successful")
}else{
println("Merge Failed")
sh 'exit 123'
}
println("Result is"+ mergeResult)
}else{
println("merging not possible")
currentBuild.result = "FAILURE"
sh 'exit 1';
}
}
}
}
def isChangeInUI(){
def num_of_ui_changes;
withCredentials([usernameColonPassword(credentialsId: '550650ab-ee92-4d31-a3f4-91a11d5388a3', variable: 'Credentials')]) {
num_of_ui_changes = sh(returnStdout: true, script: '''
curl -u $Credentials -X GET https://patch-diff.githubusercontent.com/raw/marklogic/marklogic-data-hub/pull/$CHANGE_ID.diff | grep -c '^diff.*/ui' || true
''')
}
num_of_ui_changes as Integer != 0
}
def isPRMergable(){
return !params.regressions && env.TESTS_PASSED?.toBoolean() && env.UNIT_TESTS_PASSED?.toBoolean() &&
(
env.NO_UI_TESTS || (env.UI_TESTS_PASSED?.toBoolean() && env.CYPRESSE2E_TESTS_PASSED?.toBoolean())
)
}
void singleNodeTestOnLinux(String type,String mlVersion){
cleanWs deleteDirs: true, patterns: [[pattern: 'data-hub/**', type: 'EXCLUDE']]
props = readProperties file:'data-hub/pipeline.properties';
copyRPM type,mlVersion
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
sh 'export JAVA_HOME="$JAVA_HOME_DIR";export M2_HOME="$MAVEN_HOME";export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH";cd $WORKSPACE/data-hub;./gradlew -g ./cache-build clean;set +e;./gradlew -g ./cache-build marklogic-data-hub:bootstrapAndTest -Dorg.gradle.jvmargs=-Xmx1g -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew -g ./cache-build ml-data-hub:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew -g ./cache-build web:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/;sleep 10s;./gradlew -g ./cache-build marklogic-data-hub-central:test -i --stacktrace -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/ |& tee console.log;sleep 10s;'
junit '**/TEST-*.xml'
def output=readFile 'data-hub/console.log'
def result=false;
if(output.contains("npm ERR!")){
result=true;
}
if(result){
currentBuild.result='UNSTABLE'
}
}
void fullCycleSingleNodeTestOnLinux(String type,String mlVersion){
cleanWs deleteDirs: true, patterns: [[pattern: 'data-hub/**', type: 'EXCLUDE']]
props = readProperties file:'data-hub/pipeline.properties';
copyRPM type,mlVersion
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
sh 'export JAVA_HOME="$JAVA_HOME_DIR";export M2_HOME="$MAVEN_HOME";export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH";cd $WORKSPACE/data-hub;./gradlew -g ./cache-build clean publishToMavenLocal ml-data-hub:testFullCycle -i --stacktrace'
junit '**/TEST-*.xml'
}
void invokeDhsTestJob(){
cleanWs deleteDirs: true, patterns: [[pattern: 'data-hub/**', type: 'EXCLUDE']]
}
void invokeDhcceTestJob(){
cleanWs deleteDirs: true, patterns: [[pattern: 'data-hub/**', type: 'EXCLUDE']]
build job: 'DHCCE/dhcce-test', parameters: [string(name: 'DHF_BRANCH', value: env.BRANCH_NAME)], propagate: true, wait: true
}
void postStage(String status){
println("${STAGE_NAME} " + status)
def email;
if (env.CHANGE_AUTHOR) {
def author = env.CHANGE_AUTHOR.toString().trim().toLowerCase()
email = getEmailFromGITUser author
} else {email = Email}
if(env.CHANGE_URL){
sendMail email, "<h3>All the ${STAGE_NAME} " + status + " on <a href=${CHANGE_URL}>$BRANCH_NAME</a> and the next stage is Code-review.</h3><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>", false, "${STAGE_NAME} for $BRANCH_NAME " + status
}
else {
sendMail email, "<h3>All the ${STAGE_NAME} " + status + " the next stage is Code-review.</h3><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>", false, "${STAGE_NAME} for $BRANCH_NAME " + status
}
}
void postTestsSuccess(){
println("Core Unit Tests Completed")
script{
def email;
if(env.CHANGE_AUTHOR){
def author=env.CHANGE_AUTHOR.toString().trim().toLowerCase()
email=getEmailFromGITUser author
}else{
email=Email
}
sendMail email,'<h3>All the Core Unit Tests Passed on <a href=${CHANGE_URL}>$BRANCH_NAME</a> and the next stage is Code-review.</h3><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>',false,'Unit Tests for $BRANCH_NAME Passed'
}
}
void postCoreTestsUnstable(){
println("Unit Tests Failed")
sh 'mkdir -p MLLogs;mkdir -p MLLogs/container1;docker cp ml1.marklogic.com:/var/opt/MarkLogic/Logs/. $WORKSPACE/MLLogs/container1/;mkdir -p MLLogs/container2;docker cp ml2.marklogic.com:/var/opt/MarkLogic/Logs/. $WORKSPACE/MLLogs/container2/;mkdir -p MLLogs/container3;docker cp ml3.marklogic.com:/var/opt/MarkLogic/Logs/. $WORKSPACE/MLLogs/container3/;'
archiveArtifacts artifacts: 'MLLogs/**/*'
script{
def email;
if(env.CHANGE_AUTHOR){
def author=env.CHANGE_AUTHOR.toString().trim().toLowerCase()
email=getEmailFromGITUser author
}else{
email=Email
}
sendMail email,'<h3>Some of the Core Unit Tests Failed on <a href=${CHANGE_URL}>$BRANCH_NAME</a>. Please look into the issues and fix it.</h3><h4><a href=${JENKINS_URL}/blue/organizations/jenkins/Datahub_CI/detail/$JOB_BASE_NAME/$BUILD_ID/tests><font color=red>Check the Test Report</font></a></h4><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>',false,'Core Unit Tests for $BRANCH_NAME Failed'
}
}
void postTestsUnstable(){
println("Unit Tests Failed")
sh 'mkdir -p MLLogs;cp -r /var/opt/MarkLogic/Logs/* $WORKSPACE/MLLogs/'
archiveArtifacts artifacts: 'MLLogs/**/*'
script{
def email;
if(env.CHANGE_AUTHOR){
def author=env.CHANGE_AUTHOR.toString().trim().toLowerCase()
email=getEmailFromGITUser author
}else{
email=Email
}
sendMail email,'<h3>Some of the Unit Tests Failed on <a href=${CHANGE_URL}>$BRANCH_NAME</a>. Please look into the issues and fix it.</h3><h4><a href=${JENKINS_URL}/blue/organizations/jenkins/Datahub_CI/detail/$JOB_BASE_NAME/$BUILD_ID/tests><font color=red>Check the Test Report</font></a></h4><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4>',false,'Unit Tests for $BRANCH_NAME Failed'
}
}
def cypressSetup(String type, String mlVersion){
sh 'rm -rf $WORKSPACE/xdmp/src/*'
copyRPM type,mlVersion
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
copyArtifacts filter: '**/*central*.war', fingerprintArtifacts: true, flatten: true, projectName: 'Datahub_CI/develop', selector: specific('${BUILD_NUMBER}')
sh '''
sudo mladmin stop-hubcentral
cd $WORKSPACE
WAR_NAME=$(basename *central*.war )
nohup java -jar $WORKSPACE/$WAR_NAME &
'''
//wait for prem to start
timeout(10) {waitUntil initialRecurrencePeriod: 15000, { sh(script: 'ps aux | grep ".central.*\\.war" | grep -v grep | grep -v timeout', returnStatus: true) == 0 }}
sh(script:'''#!/bin/bash
export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;
export M2_LOCAL_REPO=$WORKSPACE/$M2_HOME_REPO
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;
export PATH=$M2_LOCAL_REPO:$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH;
rm -rf $M2_LOCAL_REPO || true
mkdir -p $M2_LOCAL_REPO
cd $WORKSPACE/data-hub;
./gradlew publishToMavenLocal -Dmaven.repo.local=$M2_LOCAL_REPO -PnodeDistributionBaseUrl=http://node-mirror.eng.marklogic.com:8080/
'''
)
sh(script:'''
#!/bin/bash
export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;
export GRADLE_USER_HOME=$WORKSPACE$GRADLE_DIR;
export M2_LOCAL_REPO=$WORKSPACE/$M2_HOME_REPO
export PATH=$M2_LOCAL_REPO:$JAVA_HOME/bin:$GRADLE_USER_HOME:$PATH;
cd $WORKSPACE/data-hub;
rm -rf $GRADLE_USER_HOME/caches;
cd marklogic-data-hub-central/ui/e2e;
repo="maven {url '"$M2_LOCAL_REPO"'}"
sed -i "/repositories {/a$repo" hc-qa-project/build.gradle
chmod +x setup.sh;
./setup.sh dhs=false mlHost=localhost mlSecurityUsername=admin mlSecurityPassword=admin;
'''
)
}
def runFFTests(){
sleep time: 12, unit: 'MINUTES'
waitUntil(initialRecurrencePeriod: 120000) {
return fFsetupcomplete
}
env.cypressFFBaseUrl=cypressFFBaseUrl.trim()
env.mlFFHost=mlFFHost.trim()
bat script: """
setlocal
set ERRORLEVEL=0
set PATH=C:\\Program Files (x86)\\OpenJDK\\jdk-8.0.262.10-hotspot\\bin;$PATH
set CYPRESS_BASE_URL=${cypressFFBaseUrl}
set mlHost=${mlFFHost}
cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e
npm run cy:run-firefox-headed -- --config baseUrl=${cypressFFBaseUrl} --env mlHost=${mlFFHost} >> e2e_err.log
"""
findText(textFinders: [textFinder('npm error')])
junit '**/e2e/**/*.xml'
}
def cypressE2EOnPremMacChromeTests(){
sleep time: 12, unit: 'MINUTES'
waitUntil(initialRecurrencePeriod: 120000) {
return chMacsetupcomplete
}
env.cypressChMacBaseUrl=cypressChMacBaseUrl.trim()
env.mlChMacHost=mlChMacHost.trim()
sh(script:'''
export PATH=/usr/local/bin:$PATH
cd $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e
npm run cy:run-chrome-headed -- --config baseUrl=${cypressChMacBaseUrl} --env mlHost=${mlChMacHost} >> e2e_err.log
''')
findText(textFinders: [textFinder('npm error')])
junit '**/e2e/**/*.xml'
}
def cypressE2ePostFailed(){
sh 'rm -rf ${STAGE_NAME} || true;mkdir -p ${STAGE_NAME}/MLLogs;cp -r /var/opt/MarkLogic/Logs/* $WORKSPACE/MLLogs/ || true; mkdir -p ${STAGE_NAME}/E2ELogs; cp -r $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e/cypress/videos ${STAGE_NAME}/E2ELogs/;cp -r $WORKSPACE/data-hub/marklogic-data-hub-central/ui/e2e/cypress/screenshots ${STAGE_NAME}/E2ELogs/'
archiveArtifacts artifacts: "**/E2ELogs/**/videos/**/*,**/E2ELogs/**/screenshots/**/*,${STAGE_NAME}/MLLogs/**/*"
println("$STAGE_NAME Failed")
sendMail Email,"<h3>$STAGE_NAME Server on Linux Platform </h3><h4><a href=${JENKINS_URL}/blue/organizations/jenkins/Datahub_CI/detail/$JOB_BASE_NAME/$BUILD_ID/tests><font color=red>Check the Test Report</font></a></h4><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4><h4>Please create bugs for the failed regressions and fix them</h4>",false,"$BRANCH_NAME branch $STAGE_NAME Failed"
}
def cypressE2ePostFailedWin(){
bat '''
rmdir /s /q "%STAGE_NAME%" || true
mkdir "%STAGE_NAME%\\MLLogs"
xcopy /s /e /i "C:\\Program Files\\MarkLogic\\Data\\Logs\\*" "%WORKSPACE%\\MLLogs\\" || true
mkdir "%STAGE_NAME%\\E2ELogs\\videos"
mkdir "%STAGE_NAME%\\E2ELogs\\screenshots"
xcopy /s /e /i "%WORKSPACE%\\data-hub\\marklogic-data-hub-central\\ui\\e2e\\cypress\\videos" "%STAGE_NAME%\\E2ELogs\\videos"
xcopy /s /e /i "%WORKSPACE%\\data-hub\\marklogic-data-hub-central\\ui\\e2e\\cypress\\screenshots" "%STAGE_NAME%\\E2ELogs\\screenshots"
'''
archiveArtifacts artifacts: "**/E2ELogs/**/videos/**/*,**/E2ELogs/**/screenshots/**/*,${STAGE_NAME}/MLLogs/**/*"
println("$STAGE_NAME Failed")
sendMail Email,"<h3>$STAGE_NAME Server on Windows Platform </h3><h4><a href=${JENKINS_URL}/blue/organizations/jenkins/Datahub_CI/detail/$JOB_BASE_NAME/$BUILD_ID/tests><font color=red>Check the Test Report</font></a></h4><h4><a href=${RUN_DISPLAY_URL}>Check the Pipeline View</a></h4><h4> <a href=${BUILD_URL}/console> Check Console Output Here</a></h4><h4>Please create bugs for the failed regressions and fix them</h4>",false,"$BRANCH_NAME branch $STAGE_NAME Failed"
}
pipeline{
agent none;
options {
checkoutToSubdirectory 'data-hub'
buildDiscarder logRotator(artifactDaysToKeepStr: '7', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '')
}
environment{
JAVA_HOME_DIR="/home/builder/java/openjdk-1.8.0-262"
GRADLE_DIR="/.gradle"
MAVEN_HOME="/usr/local/maven"
M2_HOME_REPO="/repository"
NODE_HOME_DIR="/home/builder/nodeJs/node-v12.18.3-linux-x64"
DMC_USER = credentials('MLBUILD_USER')
DMC_PASSWORD= credentials('MLBUILD_PASSWORD')
}
parameters{
string(name: 'Email', defaultValue: '[email protected],[email protected],[email protected],[email protected],[email protected]' ,description: 'Who should I say send the email to?')
booleanParam(name: 'regressions', defaultValue: false, description: 'indicator if build is for regressions')
}
stages{
stage('Pre-Build-Check'){
agent { label 'dhfLinuxAgent'}
steps{ PreBuildCheck() }
post{failure{postStage('Stage Failed')}}
}
stage('Build-datahub'){
agent { label 'dhfLinuxAgent'}
steps{BuildDatahub()}
post{failure {postStage('Stage Failed')}}
}
stage('tests'){
parallel{
stage('Core-Unit-Tests'){
agent { label 'dhfLinuxAgent'}
steps{Tests()}
post{
success {
script{env.TESTS_PASSED=true}
postTestsSuccess()
}
unstable {
postCoreTestsUnstable()
}
}
}
stage('Unit-Tests'){
agent { label 'dhfLinuxAgent'}
steps{UnitTest()}
post{
always{
sh 'rm -rf $WORKSPACE/xdmp'
}
success {
script{ env.UNIT_TESTS_PASSED=true }
postTestsSuccess()
}
unstable {
postTestsUnstable()
}
}
}
stage('cypresse2e'){
when {
expression {return !env.NO_UI_TESTS}
beforeAgent true
}
agent { label 'dhfLinuxAgent'}
steps{timeout(time: 3, unit: 'HOURS'){
catchError(buildResult: 'SUCCESS', catchInterruptions: true, stageResult: 'FAILURE') {runCypressE2e('npm run cy:run')}
}}
post{
always{sh 'rm -rf $WORKSPACE/xdmp;sudo mladmin stop-hubcentral' }
success {
script{env.CYPRESSE2E_TESTS_PASSED=true}
postStage('Tests Passed')
}
unstable {
sh 'rm -rf ${STAGE_NAME}|| true;mkdir -p ${STAGE_NAME}/MLLogs;cp -r /var/opt/MarkLogic/Logs/* $WORKSPACE/${STAGE_NAME}/MLLogs/ || true; mkdir -p ${STAGE_NAME}/E2ELogs; cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/videos ${STAGE_NAME}/E2ELogs/;cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/screenshots ${STAGE_NAME}/E2ELogs/'
archiveArtifacts artifacts: "**/E2ELogs/**/videos/**/*,**/E2ELogs/**/screenshots/**/*,${STAGE_NAME}/MLLogs/**/*"
postStage('Tests Failed')
}
failure{
sh 'rm -rf ${STAGE_NAME} || true;mkdir -p ${STAGE_NAME}/MLLogs;cp -r /var/opt/MarkLogic/Logs/* $WORKSPACE/${STAGE_NAME}/MLLogs/ || true; mkdir -p ${STAGE_NAME}/E2ELogs; cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/videos ${STAGE_NAME}/E2ELogs/;cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/screenshots ${STAGE_NAME}/E2ELogs/'
archiveArtifacts artifacts: "**/E2ELogs/**/videos/**/*,**/E2ELogs/**/screenshots/**/*,${STAGE_NAME}/MLLogs/**/*"
postStage('Stage Failed')
}}
}
/* stage('cypresse2e-firefox') {
when {
expression { return params.regressions }
beforeAgent true
}
//agent { label 'dhfLinuxAgent' }
agent { label 'rh7v-10-dhf-5.marklogic.com' }
steps{timeout(time: 3, unit: 'HOURS'){
catchError(buildResult: 'SUCCESS', catchInterruptions: true, stageResult: 'FAILURE') {runCypressE2e('npm run cy:run-firefox-headed')}
}}
post { always { sh 'rm -rf $WORKSPACE/xdmp' }
success {postStage('Tests Passed')}
unstable {
sh 'rm -rf ${STAGE_NAME} || true;mkdir -p ${STAGE_NAME}/MLLogs;cp -r /var/opt/MarkLogic/Logs/* $WORKSPACE/MLLogs/ || true; mkdir -p ${STAGE_NAME}/E2ELogs; cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/videos ${STAGE_NAME}/E2ELogs/;cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/screenshots ${STAGE_NAME}/E2ELogs/'
*/
// archiveArtifacts artifacts: "**/E2ELogs/**/videos/**/*,**/E2ELogs/**/screenshots/**/*,${STAGE_NAME}/MLLogs/**/*"
/* postStage('Tests Failed')
}
failure{
sh 'rm -rf ${STAGE_NAME} || true;mkdir -p ${STAGE_NAME}/MLLogs;cp -r /var/opt/MarkLogic/Logs/* $WORKSPACE/MLLogs/ || true; mkdir -p ${STAGE_NAME}/E2ELogs; cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/videos ${STAGE_NAME}/E2ELogs/;cp -r data-hub/marklogic-data-hub-central/ui/e2e/cypress/screenshots ${STAGE_NAME}/E2ELogs/'
*/
// archiveArtifacts artifacts: "**/E2ELogs/**/videos/**/*,**/E2ELogs/**/screenshots/**/*,${STAGE_NAME}/MLLogs/**/*"
/* postStage('Stage Failed')
}}