forked from cyberark/conjur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
1436 lines (1299 loc) · 50.6 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
#!/usr/bin/env groovy
/*
NOTE TO DEVELOPERS:
When developing, you'll often need to use the CI to test to verify work, but
only care about the result of a single test, or a few tests. In this case, you
can dramatically cut down your cycle time (to about 10 minutes) by running only
the relevant tests.
There are two ways to do this:
1. (most common) Temporarily edit the Jenkinsfile. You'll need to undo your
change when your PR is ready for review. Simply edit the default value of
the 'RUN_ONLY' parameter (defined in the parameters block below) to a
space-separated list consisting of test names from the list below.
2. Re-run the same code (perhaps because of a flaky test) directly in Jenkins.
In this case, go to your branch in Jenkins (not Blue Ocean). For example:
https://jenkins.conjur.net/job/cyberark--conjur/job/<MY-NICE_BRANCH>
And click on "Build with Parameters" in the left nav. In the RUN_ONLY text
input, enter a list of space-separated test names that you want to run, from
the list below:
LIST OF ALL TEST NAMES
These are defined in runConjurTests, and also include the one-offs
"azure_authenticator" and "gcp_authenticator":
rspec
authenticators_config
authenticators_status
authenticators_ldap
authenticators_oidc
authenticators_jwt
policy
proxy
api
rotators
authenticators_k8s
rspec_audit
policy_parser
conjur_rack
azure_authenticator
gcp_authenticator
*/
@Library("product-pipelines-shared-library") _
// runSecurityScans uses 2 environment variables to determine where in DefectDojo to
// upload the results of the scans. We have to set those variables in both the regular
// pipeline and the promote block, so use variables for it to keep them consistent.
def productName = 'Conjur'
def productTypeName = 'Conjur OSS'
// Automated release, promotion and dependencies
properties([
// Include the automated release parameters for the build
release.addParams(),
// Dependencies of the project that should trigger builds
dependencies(['conjur-enterprise/conjur-base-image',
'conjur-enterprise/conjur-api-ruby',
'conjurinc/debify'])
])
// Performs release promotion. No other stages will be run
if (params.MODE == "PROMOTE") {
release.promote(params.VERSION_TO_PROMOTE) { infrapool, sourceVersion, targetVersion, assetDirectory ->
env.INFRAPOOL_PRODUCT_NAME = "${productName}"
env.INFRAPOOL_DD_PRODUCT_TYPE_NAME = "${productTypeName}"
def scans = [:]
scans["Conjur AMD64"] = {
stage("Conjur AMD64 scans") {
runSecurityScans(infrapool,
image: "registry.tld/cyberark/conjur:${sourceVersion}-amd64",
buildMode: params.MODE,
branch: env.BRANCH_NAME,
arch: 'linux/amd64')
}
}
scans["Conjur ARM64"] = {
stage("Conjur ARM64 scans") {
runSecurityScans(infrapool,
image: "registry.tld/cyberark/conjur:${sourceVersion}-arm64",
buildMode: params.MODE,
branch: env.BRANCH_NAME,
arch: 'linux/arm64')
}
}
scans["Conjur UBI AMD64"] = {
stage("Conjur UBI AMD64 scans") {
runSecurityScans(infrapool,
image: "registry.tld/conjur-ubi:${sourceVersion}-amd64",
buildMode: params.MODE,
branch: env.BRANCH_NAME,
arch: 'linux/amd64')
}
}
scans["Conjur UBI ARM64"] = {
stage("Conjur UBI ARM64 scans") {
runSecurityScans(infrapool,
image: "registry.tld/conjur-ubi:${sourceVersion}-arm64",
buildMode: params.MODE,
branch: env.BRANCH_NAME,
arch: 'linux/arm64')
}
}
parallel(scans)
infrapool.agentSh """
docker pull registry.tld/cyberark/conjur:${sourceVersion}-amd64
docker tag registry.tld/cyberark/conjur:${sourceVersion}-amd64 conjur:${sourceVersion}-amd64
docker pull registry.tld/cyberark/conjur:${sourceVersion}-arm64
docker tag registry.tld/cyberark/conjur:${sourceVersion}-arm64 conjur:${sourceVersion}-arm64
docker pull registry.tld/conjur-ubi:${sourceVersion}-amd64
docker tag registry.tld/conjur-ubi:${sourceVersion}-amd64 conjur-ubi:${sourceVersion}-amd64
docker pull registry.tld/conjur-ubi:${sourceVersion}-arm64
docker tag registry.tld/conjur-ubi:${sourceVersion}-arm64 conjur-ubi:${sourceVersion}-arm64
# Promote both images for AMD64 and ARM64
summon -f ./secrets.yml ./publish-images.sh --promote --redhat --base-version=${sourceVersion} --version=${targetVersion}
summon -f ./secrets.yml ./publish-images.sh --promote --base-version=${sourceVersion} --version=${targetVersion} --arch=arm64
# Promote manifest that links above images
summon -f ./secrets.yml ./publish-manifest.sh --promote --dockerhub --base-version=${sourceVersion} --version=${targetVersion}
"""
build(
job: 'Conjur-Enterprise/Conjur-Enterprise-conjurops/main/Conjur-Enterprise-conjurops-main-full/master',
parameters:[
string(name: 'conjur_oss_source_image', value: "cyberark/conjur:${targetVersion}")
],
wait: false
)
}
// Copy Github Enterprise release to Github
release.copyEnterpriseRelease(params.VERSION_TO_PROMOTE)
return
}
pipeline {
agent { label 'conjur-enterprise-common-agent' }
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr: '30'))
timeout(time: 2, unit: 'HOURS')
}
// "parameterizedCron" is defined by this native Jenkins plugin:
// https://plugins.jenkins.io/parameterized-scheduler/
// "getDailyCronString" is defined by us (URL is wrapped):
// https://github.com/conjurinc/jenkins-pipeline-library/blob/master/vars/
// getDailyCronString.groovy
triggers {
parameterizedCron(getDailyCronString("%NIGHTLY=true"))
}
parameters {
booleanParam(
name: 'NIGHTLY',
defaultValue: false, // Temporarily set to true for all branches
description: 'Run tests on all agents and environment including: FIPS'
)
string(
name: 'RUN_ONLY',
description:
'Run only one (or a few) test for development. Space-separated list, ' +
'empty to run all tests. See Jenkinsfile for details.',
// See note at top of file for temporarily changing this value during
// development.
defaultValue: ''
)
string(
name: 'INFRAPOOL_CUCUMBER_FILTER_TAGS',
description: 'Filter which cucumber tags will run (e.g. "not @performance")',
defaultValue: defaultCucumberFilterTags(env)
)
}
environment {
// Sets the MODE to the specified or autocalculated value as appropriate
MODE = release.canonicalizeMode()
TAG_SHA = tagWithSHA()
// Values to direct scan results to the right place in DefectDojo
INFRAPOOL_PRODUCT_NAME = "${productName}"
INFRAPOOL_DD_PRODUCT_TYPE_NAME = "${productTypeName}"
}
stages {
stage('Scan for internal URLs') {
steps {
script {
detectInternalUrls()
}
}
}
// Pre-allocate agents to fail fast if there's an issue with the pool
// and to pre-configure the git environment before changes occur.
stage('Get InfraPool Agents') {
steps {
script {
INFRAPOOL_EXECUTORV2_AGENTS = getInfraPoolAgent.connected(type: "ExecutorV2", quantity: 3, duration: 1)
INFRAPOOL_EXECUTORV2_AGENT_0 = INFRAPOOL_EXECUTORV2_AGENTS[0]
INFRAPOOL_EXECUTORV2_AGENT_1 = INFRAPOOL_EXECUTORV2_AGENTS[1]
INFRAPOOL_EXECUTORV2_AGENT_2 = INFRAPOOL_EXECUTORV2_AGENTS[2]
INFRAPOOL_EXECUTORV2ARM_AGENT_0 = getInfraPoolAgent.connected(type: "ExecutorV2ARM", quantity: 1, duration: 1)[0]
INFRAPOOL_EXECUTORV2_RHELEE_AGENTS = getInfraPoolAgent.connected(type: "ExecutorV2RHELEE", quantity: 3, duration: 1)
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0 = INFRAPOOL_EXECUTORV2_RHELEE_AGENTS[0]
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_1 = INFRAPOOL_EXECUTORV2_RHELEE_AGENTS[1]
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_2 = INFRAPOOL_EXECUTORV2_RHELEE_AGENTS[2]
INFRAPOOL_AZURE_EXECUTORV2_AGENT_0 = getInfraPoolAgent.connected(type: "AzureExecutorV2", quantity: 1, duration: 1)[0]
INFRAPOOL_GCP_EXECUTORV2_AGENT_0 = getInfraPoolAgent.connected(type: "GcpExecutorV2", quantity: 1, duration: 1)[0]
// Break the total number of tests into a subset of tests.
// This will give 3 nested lists of tests to run, which is
// distributed over 3 jenkins agents.
NESTED_ARRAY_OF_TESTS_TO_RUN = collateTests(INFRAPOOL_EXECUTORV2_AGENT_0)
}
}
}
// Aborts any builds triggered by another project that wouldn't include any changes
stage ("Skip build if triggering job didn't create a release") {
when {
expression {
MODE == "SKIP"
}
}
steps {
script {
currentBuild.result = 'ABORTED'
error("Aborting build because this build was triggered from upstream, but no release was built")
}
}
}
// Generates a VERSION file based on the current build number and latest version in CHANGELOG.md
stage('Validate Changelog and set version') {
steps {
script {
updateVersion(INFRAPOOL_EXECUTORV2_AGENT_0, "CHANGELOG.md", "${BUILD_NUMBER}")
updateVersion(INFRAPOOL_EXECUTORV2ARM_AGENT_0, "CHANGELOG.md", "${BUILD_NUMBER}")
INFRAPOOL_EXECUTORV2_AGENT_0.agentStash name: 'version_info', includes: 'VERSION'
}
}
}
stage('Validate Changelog') {
when {
expression { params.RUN_ONLY == '' }
}
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh 'ci/parse-changelog'
}
}
}
stage('Mark Workspace as Safe Git Directory'){
steps {
script {
sh "git config --global --add safe.directory $WORKSPACE"
}
}
}
stage('Build and test Conjur') {
when {
// Run tests only when ANY of the following is true:
// 1. A non-markdown file has changed.
// 2. It's running on the master branch (which includes nightly builds).
// 3. It's a tag-triggered build.
anyOf {
// Note: You cannot use "when"'s changeset condition here because it's
// not powerful enough to express "_only_ md files have changed".
// Dropping down to a git script was the easiest alternative.
expression {
0 == sh(
returnStatus: true,
// A non-markdown file has changed.
script: '''
git diff origin/master --name-only |
grep -v "^.*\\.md$" > /dev/null
'''
)
}
// Always run the full pipeline on the master branch (which includes
// nightly builds)
branch "master"
// Always run the full pipeline on tags
buildingTag()
}
}
stages {
stage('Build Docker Image') {
parallel {
stage('Build AMD64 image') {
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh './build.sh --jenkins'
}
}
}
stage('Build ARM64 image') {
steps {
script {
INFRAPOOL_EXECUTORV2ARM_AGENT_0.agentSh './build.sh --jenkins'
}
}
}
}
}
stage('Push images to internal registry') {
parallel {
stage('Push images AMD64 image') {
steps {
script {
// Push images to the internal registry so that they can be used
// by tests, even if the tests run on a different executor.
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh './publish-images.sh --internal'
}
}
}
stage('Push images ARM64 image') {
steps {
script {
// Push images to the internal registry so that they can be used
// by tests, even if the tests run on a different executor.
INFRAPOOL_EXECUTORV2ARM_AGENT_0.agentSh './publish-images.sh --internal --arch=arm64'
}
}
}
}
}
stage('Push multi-arch manifest to internal registry') {
steps {
script {
// Push multi-architecture manifest to the internal registry.
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh './publish-manifest.sh --internal'
}
}
}
stage('Run security scans') {
parallel {
stage('AMD64 Ubuntu-based Docker image scans') {
steps {
runSecurityScans(INFRAPOOL_EXECUTORV2_AGENT_0,
image: "registry.tld/conjur:${TAG_SHA}",
buildMode: MODE,
branch: env.BRANCH_NAME,
arch: "linux/amd64")
}
}
stage('ARM64 Ubuntu-based Docker image scans') {
steps {
runSecurityScans(INFRAPOOL_EXECUTORV2ARM_AGENT_0,
image: "registry.tld/conjur:${TAG_SHA}",
buildMode: MODE,
branch: env.BRANCH_NAME,
arch: "linux/arm64")
}
}
stage('AMD64 UBI-based Docker image scans') {
steps {
runSecurityScans(INFRAPOOL_EXECUTORV2_AGENT_1,
image: "registry.tld/conjur-ubi:${TAG_SHA}",
buildMode: MODE,
branch: env.BRANCH_NAME,
arch: "linux/amd64")
}
}
stage('ARM64 UBI-based Docker image scans') {
steps {
runSecurityScans(INFRAPOOL_EXECUTORV2ARM_AGENT_0,
image: "registry.tld/conjur-ubi:${TAG_SHA}",
buildMode: MODE,
branch: env.BRANCH_NAME,
arch: "linux/arm64")
}
}
stage('AMD64 Conjur-Test Docker image scans') {
steps {
runSecurityScans(INFRAPOOL_EXECUTORV2_AGENT_2,
image: "registry.tld/conjur-test:${TAG_SHA}",
buildMode: MODE,
branch: env.BRANCH_NAME,
arch: "linux/amd64")
}
}
stage('ARM64 Conjur-Test Docker image scans') {
steps {
runSecurityScans(INFRAPOOL_EXECUTORV2ARM_AGENT_0,
image: "registry.tld/conjur-test:${TAG_SHA}",
buildMode: MODE,
branch: env.BRANCH_NAME,
arch: "linux/arm64")
}
}
}
}
// TODO: Add comments explaining which env vars are set here.
stage('Prepare For CodeClimate Coverage Report Submission') {
when {
expression { params.RUN_ONLY == '' }
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh 'mkdir -p coverage'
sh 'mkdir -p coverage'
env.CODE_CLIMATE_PREPARED = "true"
}
}
}
}
// Run outside parallel block to avoid external pressure
stage('RSpec - Standard agent tests') {
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh 'ci/test rspec'
}
}
}
// Run outside parallel block to reduce main Jenkins executor load.
stage('Nightly Only') {
when {
expression { params.NIGHTLY }
}
environment {
INFRAPOOL_CUCUMBER_FILTER_TAGS = "${params.INFRAPOOL_CUCUMBER_FILTER_TAGS}"
}
stages {
stage("RSpec - EE FIPS agent tests") {
steps {
script {
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0.agentSh(script: 'cat /etc/os-release', label: 'RHEL version')
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0.agentSh(script: 'docker --version', label: 'Docker version')
addNewImagesToAgent(INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0)
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0.agentUnstash name: 'version_info'
// Catch errors so remaining steps always run.
catchError {
// Run outside parallel block to avoid external pressure
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0.agentSh "ci/test rspec"
}
}
}
}
stage('EE FIPS parallel') {
parallel {
stage('EE FIPS agent tests') {
when {
expression {
testShouldRunOnAgent(
params.RUN_ONLY,
runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[0])
)
}
}
steps {
script {
addNewImagesToAgent(INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0)
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0.agentUnstash name: 'version_info'
runConjurTests(
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0,
params.RUN_ONLY,
NESTED_ARRAY_OF_TESTS_TO_RUN[0]
)
}
}
post {
always {
script {
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_0.agentStash(
name: 'testResultEE',
includes: '''
cucumber/*/*.*,
container_logs/*/*,
spec/reports/*.xml,
spec/reports-audit/*.xml,
gems/conjur-rack/spec/reports/*.xml,
cucumber/*/features/reports/**/*.xml
'''
)
}
}
}
}
// Run a subset of tests on a second agent to prevent oversubscribing the hardware
stage('EE FIPS agent2 tests') {
when {
expression {
testShouldRunOnAgent(
params.RUN_ONLY,
runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[1])
)
}
}
environment {
INFRAPOOL_CUCUMBER_FILTER_TAGS = "${params.INFRAPOOL_CUCUMBER_FILTER_TAGS}"
}
steps {
script {
addNewImagesToAgent(INFRAPOOL_EXECUTORV2_RHELEE_AGENT_1)
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_1.agentUnstash name: 'version_info'
runConjurTests(
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_1,
params.RUN_ONLY,
NESTED_ARRAY_OF_TESTS_TO_RUN[1]
)
}
}
post {
always {
script {
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_1.agentStash(
name: 'testResultEE2',
includes: '''
cucumber/*/*.*,
container_logs/*/*,
spec/reports/*.xml,
spec/reports-audit/*.xml,
cucumber/*/features/reports/**/*.xml
'''
)
}
}
}
}
// Run a subset of tests on a second agent to prevent oversubscribing the hardware
stage('EE FIPS agent3 tests') {
when {
expression {
testShouldRunOnAgent(
params.RUN_ONLY,
runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[2])
)
}
}
environment {
INFRAPOOL_CUCUMBER_FILTER_TAGS = "${params.INFRAPOOL_CUCUMBER_FILTER_TAGS}"
}
steps {
script {
addNewImagesToAgent(INFRAPOOL_EXECUTORV2_RHELEE_AGENT_2)
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_2.agentUnstash name: 'version_info'
runConjurTests(
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_2,
params.RUN_ONLY,
NESTED_ARRAY_OF_TESTS_TO_RUN[2]
)
}
}
post {
always {
script {
INFRAPOOL_EXECUTORV2_RHELEE_AGENT_2.agentStash(
name: 'testResultEE3',
includes: '''
cucumber/*/*.*,
container_logs/*/*,
spec/reports/*.xml,
spec/reports-audit/*.xml,
cucumber/*/features/reports/**/*.xml
'''
)
}
}
}
}
}
}
}
post {
always {
script {
if (testShouldRunOnAgent(params.RUN_ONLY, runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[0]))) {
dir('ee-test'){
INFRAPOOL_EXECUTORV2_AGENT_0.agentUnstash 'testResultEE'
}
}
if (testShouldRunOnAgent(params.RUN_ONLY, runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[1]))) {
dir('ee-test'){
INFRAPOOL_EXECUTORV2_AGENT_0.agentUnstash 'testResultEE2'
}
}
if (testShouldRunOnAgent(params.RUN_ONLY, runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[2]))) {
dir('ee-test'){
INFRAPOOL_EXECUTORV2_AGENT_0.agentUnstash 'testResultEE3'
}
}
}
archiveArtifacts(
artifacts: "ee-test/cucumber/*/*.*",
fingerprint: false,
allowEmptyArchive: true
)
archiveArtifacts(
artifacts: "ee-test/container_logs/*/*",
fingerprint: false,
allowEmptyArchive: true
)
publishHTML(
reportDir: 'ee-test/cucumber',
reportFiles: '''
api/cucumber_results.html,
authenticators_config/cucumber_results.html,
authenticators_azure/cucumber_results.html,
authenticators_ldap/cucumber_results.html,
authenticators_oidc/cucumber_results.html,
authenticators_jwt/cucumber_results.html,
authenticators_status/cucumber_results.html
policy/cucumber_results.html,
rotators/cucumber_results.html
''',
reportName: 'EE Integration reports',
reportTitles: '',
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true
)
}
}
}
stage('Run environment tests in parallel') {
parallel {
stage('Standard agent tests') {
when {
expression {
testShouldRunOnAgent(
params.RUN_ONLY,
runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[0])
)
}
}
environment {
INFRAPOOL_CUCUMBER_FILTER_TAGS = "${params.INFRAPOOL_CUCUMBER_FILTER_TAGS}"
}
steps {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh(script: 'cat /etc/os-release', label: 'Ubuntu version')
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh(script: 'docker --version', label: 'Docker version')
runConjurTests(
INFRAPOOL_EXECUTORV2_AGENT_0,
params.RUN_ONLY,
NESTED_ARRAY_OF_TESTS_TO_RUN[0]
)
}
}
post {
always {
script {
INFRAPOOL_EXECUTORV2_AGENT_0.agentStash(
name: 'standardTestResult',
includes: '''
cucumber/*/*.*,
container_logs/*/*,
spec/reports/*.xml,
spec/reports-audit/*.xml,
cucumber/*/features/reports/**/*.xml
'''
)
}
}
}
}
// Run a subset of tests on a second agent to prevent oversubscribing the hardware
stage('Standard agent2 tests') {
when {
expression {
testShouldRunOnAgent(
params.RUN_ONLY,
runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[1])
)
}
}
environment {
INFRAPOOL_CUCUMBER_FILTER_TAGS = "${params.INFRAPOOL_CUCUMBER_FILTER_TAGS}"
}
steps {
script {
addNewImagesToAgent(INFRAPOOL_EXECUTORV2_AGENT_1)
INFRAPOOL_EXECUTORV2_AGENT_1.agentUnstash name: 'version_info'
runConjurTests(
INFRAPOOL_EXECUTORV2_AGENT_1,
params.RUN_ONLY,
NESTED_ARRAY_OF_TESTS_TO_RUN[1]
)
}
}
post {
always {
script {
INFRAPOOL_EXECUTORV2_AGENT_1.agentStash(
name: 'standardTestResult2',
includes: '''
cucumber/*/*.*,
container_logs/*/*,
spec/reports/*.xml,
spec/reports-audit/*.xml,
cucumber/*/features/reports/**/*.xml
'''
)
}
}
}
}
// Run a subset of tests on a second agent to prevent oversubscribing the hardware
stage('Standard agent3 tests') {
when {
expression {
testShouldRunOnAgent(
params.RUN_ONLY,
runSpecificTestOnAgent(params.RUN_ONLY, NESTED_ARRAY_OF_TESTS_TO_RUN[2])
)
}
}
environment {
INFRAPOOL_CUCUMBER_FILTER_TAGS = "${params.INFRAPOOL_CUCUMBER_FILTER_TAGS}"
}
steps {
script {
addNewImagesToAgent(INFRAPOOL_EXECUTORV2_AGENT_2)
INFRAPOOL_EXECUTORV2_AGENT_2.agentUnstash name: 'version_info'
runConjurTests(
INFRAPOOL_EXECUTORV2_AGENT_2,
params.RUN_ONLY,
NESTED_ARRAY_OF_TESTS_TO_RUN[2]
)
}
}
post {
always {
script {
INFRAPOOL_EXECUTORV2_AGENT_2.agentStash(
name: 'standardTestResult3',
includes: '''
cucumber/*/*.*,
container_logs/*/*,
spec/reports/*.xml,
spec/reports-audit/*.xml,
cucumber/*/features/reports/**/*.xml,
ci/test_suites/*/output/*
'''
)
}
}
}
}
stage('Azure Authenticator') {
when {
expression {
testShouldRun(params.RUN_ONLY, "azure_authenticator")
}
}
environment {
// TODO: Move this into the authenticators_azure bash script.
INFRAPOOL_AZURE_AUTHN_INSTANCE_IP = INFRAPOOL_AZURE_EXECUTORV2_AGENT_0.agentSh(
script: 'curl "http://checkip.amazonaws.com"',
returnStdout: true
).trim()
// TODO: Move this into the authenticators_azure bash script.
INFRAPOOL_SYSTEM_ASSIGNED_IDENTITY = INFRAPOOL_AZURE_EXECUTORV2_AGENT_0.agentSh(
script: 'ci/test_suites/authenticators_azure/get_system_assigned_identity.sh',
returnStdout: true
).trim()
}
steps {
script {
grantIPAccess(INFRAPOOL_AZURE_EXECUTORV2_AGENT_0)
addNewImagesToAgent(INFRAPOOL_AZURE_EXECUTORV2_AGENT_0)
INFRAPOOL_AZURE_EXECUTORV2_AGENT_0.agentUnstash name: 'version_info'
// Grant access to this Jenkins agent's IP to AWS security groups
// This is required for access to the internal docker registry
// from outside EC2.
INFRAPOOL_AZURE_EXECUTORV2_AGENT_0.agentSh(
'summon -f ci/test_suites/authenticators_azure/secrets.yml ci/test authenticators_azure'
)
}
}
post {
always {
script {
INFRAPOOL_AZURE_EXECUTORV2_AGENT_0.agentStash(
name: 'testResultAzure',
allowEmpty: true,
includes: '''
cucumber/*azure*/*.*,
container_logs/*azure*/*,
cucumber_results*.json
'''
)
// Remove this Agent's IP from IPManager's prefix list
// There are a limited number of entries, so it remove it
// rather than waiting for it to expire.
removeIPAccess(INFRAPOOL_AZURE_EXECUTORV2_AGENT_0)
}
}
}
}
/**
* GCP Authenticator -- Token Stashing -- Stage 1 of 3
*
* In this stage, a GCE instance node is allocated, a script runs
* and retrieves all the tokens that will be used in authn-gcp
* tests. The token are stashed, and later un-stashed and used in
* the stage that runs the GCP Authenticator tests. This way we can
* have a light-weight GCE instance that has no dependency on
* conjurops or git identities and is not open for SSH.
*/
stage('GCP Authenticator preparation - Allocate GCE Instance') {
when {
expression {
testShouldRun(params.RUN_ONLY, "gcp_authenticator")
}
}
steps {
echo '-- Allocating Google Compute Engine'
script {
dir('ci/test_suites/authenticators_gcp') {
INFRAPOOL_GCP_EXECUTORV2_AGENT_0.agentStash(
name: 'get_gce_tokens_script',
includes: '''
get_gce_tokens_to_files.sh,
get_tokens_to_files.sh,
tokens_config.json
'''
)
}
echo '-- Google Compute Engine allocated'
echo '-- Get compute engine instance project name from ' +
'Google metadata server.'
// TODO: Move this into get_gce_tokens_to_files.sh
env.INFRAPOOL_GCP_PROJECT = INFRAPOOL_GCP_EXECUTORV2_AGENT_0.agentSh(
script: 'curl -s -H "Metadata-Flavor: Google" \
"http://metadata.google.internal/computeMetadata/v1/project/project-id"',
returnStdout: true
).trim()
INFRAPOOL_GCP_EXECUTORV2_AGENT_0.agentUnstash(name: 'get_gce_tokens_script')
INFRAPOOL_GCP_EXECUTORV2_AGENT_0.agentSh('./get_gce_tokens_to_files.sh')
INFRAPOOL_GCP_EXECUTORV2_AGENT_0.agentStash(
name: 'authnGceTokens',
includes: 'gce_token_*',
allowEmpty:false
)
}
}
post {
failure {
script {
env.GCP_ENV_ERROR = "true"
}
}
success {
script {
env.GCE_TOKENS_FETCHED = "true"
}
echo '-- Finished fetching GCE tokens.'
}
}
}
/**
* GCP Authenticator -- Allocate Function -- Stage 2 of 3
*
* In this stage, Google SDK container executes a script to deploy a
* function, the function accepts audience in query string and
* returns a token with that audience. All the tokens required for
* testings are obtained and written to function directory, the post
* stage branch deletes the function. This stage depends on stage:
* 'GCP Authenticator preparation - Allocate GCE Instance' to set
* the GCP project env var.
*/
stage('GCP Authenticator preparation - Allocate Google Function') {
when {
expression {
testShouldRun(params.RUN_ONLY, "gcp_authenticator")
}
}
environment {
INFRAPOOL_GCP_FETCH_TOKEN_FUNCTION = "fetch_token_${BUILD_NUMBER}"
INFRAPOOL_IDENTITY_TOKEN_FILE = 'identity-token'
INFRAPOOL_GCP_OWNER_SERVICE_KEY_FILE = "sa-key-file.json"
}
steps {
echo "Waiting for GCP project name (Set by stage: " +
"'GCP Authenticator preparation - Allocate GCE Instance')"
timeout(time: 10, unit: 'MINUTES') {
waitUntil {
script {
return (
env.INFRAPOOL_GCP_PROJECT != null || env.GCP_ENV_ERROR == "true"
)
}
}
}
script {
if (env.GCP_ENV_ERROR == "true") {
error('GCP_ENV_ERROR cannot deploy function')
}
dir('ci/test_suites/authenticators_gcp') {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh('summon ./deploy_function_and_get_tokens.sh')
}
}
}
post {
success {
echo "-- Google Cloud test env is ready"
script {
env.GCP_FUNC_TOKENS_FETCHED = "true"
}
}
failure {
echo "-- GCP function deployment stage failed"
script {
env.GCP_ENV_ERROR = "true"
}
}
always {
script {
dir('ci/test_suites/authenticators_gcp') {
INFRAPOOL_EXECUTORV2_AGENT_0.agentSh '''
# Cleanup Google function
summon ./run_gcloud.sh cleanup_function.sh
'''
}
}
}
}
}
/**
* GCP Authenticator -- Run Tests -- Stage 3 of 3
*
* We have two preparation stages before running the GCP
* Authenticator tests stage. This stage waits for GCP preparation
* stages to complete, un-stashes the tokens created in stage: 'GCP
* Authenticator preparation - Allocate GCE Instance' and runs the
* gcp-authn tests.
*/
stage('GCP Authenticator - Run Tests') {
when {