-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile_CNP
More file actions
303 lines (256 loc) · 11 KB
/
Jenkinsfile_CNP
File metadata and controls
303 lines (256 loc) · 11 KB
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
#!groovy
properties([
parameters([
booleanParam(name: 'SKIP_TESTS', defaultValue: false, description: 'Skip all tests'),
booleanParam(name: 'SKIP_SONAR', defaultValue: false, description: 'Skip sonar'),
booleanParam(name: 'FAIL_FAST', defaultValue: false, description: 'Should tests fail fast'),
])
])
@Library("Infrastructure")
import uk.gov.hmcts.contino.GradleBuilder
import uk.gov.hmcts.contino.GithubAPI
def type = "java"
def product = "darts"
def component = "api"
def branchesToSync = ['demo', 'perftest', 'ithc']
def secrets = [
'darts-${env}': [
secret('GovukNotifyTestApiKey', 'GOVUK_NOTIFY_API_KEY'),
secret('app-insights-connection-string', 'app-insights-connection-string'),
secret('AzureAdB2CTenantId', 'AAD_B2C_TENANT_ID'),
secret('AzureAdB2CClientId', 'AAD_B2C_CLIENT_ID'),
secret('AzureAdB2CClientSecret', 'AAD_B2C_CLIENT_SECRET'),
secret('AzureAdB2CFuncTestROPCUsername', 'FUNC_TEST_ROPC_USERNAME'),
secret('AzureAdB2CFuncTestROPCPassword', 'FUNC_TEST_ROPC_PASSWORD'),
secret('AzureAdB2CFuncTestROPCClientId', 'AAD_B2C_ROPC_CLIENT_ID'),
secret('AzureAdB2CFuncTestROPCClientSecret', 'AAD_B2C_ROPC_CLIENT_SECRET'),
secret('api-POSTGRES-SCHEMA', 'DARTS_API_DB_SCHEMA'),
secret('AzureStorageConnectionString', 'AZURE_STORAGE_CONNECTION_STRING'),
secret('AzureADTenantId', 'AAD_TENANT_ID'),
secret('AzureADClientId', 'AAD_CLIENT_ID'),
secret('AzureADClientSecret', 'AAD_CLIENT_SECRET'),
secret('AzureADTenantIdJustice', 'AAD_TENANT_ID_JUSTICE'),
secret('AzureADClientIdJustice', 'AAD_CLIENT_ID_JUSTICE'),
secret('AzureADClientSecretJustice', 'AAD_CLIENT_SECRET_JUSTICE'),
secret('XhibitUserName', 'XHIBIT_USER_NAME'),
secret('XhibitPassword', 'XHIBIT_PASSWORD'),
secret('CppUserName', 'CPP_USER_NAME'),
secret('CppPassword', 'CPP_PASSWORD'),
secret('DarPcUserName', 'DARPC_USER_NAME'),
secret('DarPcPassword', 'DARPC_PASSWORD'),
secret('DarMidTierUserName', 'DAR_MIDTIER_USER_NAME'),
secret('DarMidTierPassword', 'DAR_MIDTIER_PASSWORD'),
secret('AzureADFunctionalTestUsername', 'AZURE_AD_FUNCTIONAL_TEST_USERNAME'),
secret('AzureADFunctionalTestPassword', 'AZURE_AD_FUNCTIONAL_TEST_PASSWORD'),
secret('DartsSystemUserEmail', 'SYSTEM_USER_EMAIL'),
secret('AzureAdB2CFuncTestROPCGlobalUsername', 'AZURE_AD_FUNCTIONAL_TEST_GLOBAL_USERNAME'),
secret('AzureAdB2CFuncTestROPCGlobalPassword', 'AZURE_AD_FUNCTIONAL_TEST_GLOBAL_PASSWORD'),
secret('ARMSasEndpoint', 'ARM_SAS_ENDPOINT'),
secret('DETSSasURLEndpoint', 'DETS_SAS_URL_ENDPOINT'),
secret('DartsInboundStorageSasUrl', 'DARTS_INBOUND_STORAGE_SAS_URL'),
secret('DartsUnstructuredStorageSasUrl', 'DARTS_UNSTRUCTURED_STORAGE_SAS_URL'),
secret('ArmServiceEntitlement', 'ARM_SERVICE_ENTITLEMENT'),
secret('ArmStorageAccountName', 'ARM_STORAGE_ACCOUNT_NAME'),
// secrets for staging DB
secret('api-POSTGRES-HOST', 'STAGING_DB_HOST'),
secret('api-POSTGRES-USER', 'STAGING_DB_USER'),
secret('api-POSTGRES-PASS', 'STAGING_DB_PASS'),
secret('api-POSTGRES-PORT', 'STAGING_DB_PORT'),
secret('api-POSTGRES-SCHEMA', 'STAGING_DB_SCHEMA'),
secret('api-POSTGRES-DATABASE', 'STAGING_DB_DATABASE'),
],
]
static LinkedHashMap<String, Object> secret(String secretName, String envVar) {
[$class : 'AzureKeyVaultSecret',
secretType : 'Secret',
name : secretName,
version : '',
envVariable: envVar
]
}
def determineDevEnvironmentDeployment() {
env.DEV_ENABLE_DARTS_PORTAL = false
env.DEV_DARTS_PORTAL_URL = "https://darts.staging.apps.hmcts.net"
env.DEV_DARTS_PORTAL_IMAGE_SUFFIX = "latest"
env.DEV_ENABLE_DARTS_GATEWAY = false
env.DEV_DARTS_GATEWAY_URL = "http://darts-gateway.staging.platform.hmcts.net"
env.DEV_DARTS_GATEWAY_IMAGE_SUFFIX = "latest"
env.NOTIFICATION_SCHEDULER_ENABLED = false
env.AUTOMATED_TASK_MODE = true
env.DEV_ENABLE_DARTS_KEDA = false
echo "1 - env.DEV_ENABLE_DARTS_PORTAL: ${env.DEV_ENABLE_DARTS_PORTAL}"
echo "1 - env.DEV_DARTS_PORTAL_URL: ${env.DEV_DARTS_PORTAL_URL}"
echo "1 - env.DEV_ENABLE_DARTS_GATEWAY: ${env.DEV_ENABLE_DARTS_GATEWAY}"
echo "1 - env.DEV_DARTS_GATEWAY_URL: ${env.DEV_DARTS_GATEWAY_URL}"
echo "1 - env.DEV_ENABLE_DARTS_KEDA: ${env.DEV_ENABLE_DARTS_KEDA}"
def githubApi = new GithubAPI(this)
if (githubApi.checkForLabel(env.BRANCH_NAME, "enable_keep_helm")) {
if (githubApi.checkForLabel(env.BRANCH_NAME, "enable_notify")) {
echo "enable_notify label detected; scheduler enabled in PR environment"
env.NOTIFICATION_SCHEDULER_ENABLED = true
env.AUTOMATED_TASK_MODE = false
}
for (label in githubApi.getLabelsbyPattern(env.BRANCH_NAME, "enable_darts_")) {
//Portal
if (label ==~ /enable_darts_portal.*/) {
env.DEV_ENABLE_DARTS_PORTAL = true
env.DEV_DARTS_PORTAL_URL = "https://darts-portal-api-pr-${env.CHANGE_ID}.dev.platform.hmcts.net"
if (label ==~ /enable_darts_portal:pr-.*/) {
env.DEV_DARTS_PORTAL_IMAGE_SUFFIX = label.replace("enable_darts_portal:", "")
echo "DARTS portal image suffix: ${env.DEV_DARTS_PORTAL_IMAGE_SUFFIX}"
}
echo "Deploying DARTS portal (${env.DEV_DARTS_PORTAL_IMAGE_SUFFIX}) instance in PR environment"
}
//Gateway
if (label ==~ /enable_darts_gateway.*/) {
env.DEV_ENABLE_DARTS_GATEWAY = true
env.DEV_DARTS_GATEWAY_URL = "https://darts-gateway-api-pr-${env.CHANGE_ID}.dev.platform.hmcts.net"
if (label ==~ /enable_darts_gateway:pr-.*/) {
env.DEV_DARTS_GATEWAY_IMAGE_SUFFIX = label.replace("enable_darts_gateway:", "")
echo "DARTS gateway image suffix: ${env.DEV_DARTS_GATEWAY_IMAGE_SUFFIX}"
}
echo "Deploying DARTS gateway (${env.DEV_DARTS_GATEWAY_IMAGE_SUFFIX}) instance in PR environment"
}
//Gateway
if (label ==~ /enable_darts_ats_keda.*/) {
env.DEV_ENABLE_DARTS_KEDA = true
echo "DARTS KEDA enabled in PR environment"
}
}
}
echo "2 - env.DEV_ENABLE_DARTS_PORTAL: ${env.DEV_ENABLE_DARTS_PORTAL}"
echo "2 - env.DEV_DARTS_PORTAL_URL: ${env.DEV_DARTS_PORTAL_URL}"
echo "2 - env.DEV_ENABLE_DARTS_GATEWAY: ${env.DEV_ENABLE_DARTS_GATEWAY}"
echo "2 - env.DEV_DARTS_GATEWAY_URL: ${env.DEV_DARTS_GATEWAY_URL}"
echo "2 - env.DEV_ENABLE_DARTS_KEDA: ${env.DEV_ENABLE_DARTS_KEDA}"
}
GradleBuilder builder = new GradleBuilder(this, product)
withPipeline(type, product, component) {
env.SKIP_TESTS = params.SKIP_TESTS
env.SKIP_SONAR = params.SKIP_SONAR
env.FAIL_FAST = params.FAIL_FAST
echo "SKIP_TESTS: ${env.SKIP_TESTS}"
echo "SKIP_SONAR: ${env.SKIP_SONAR}"
echo "FAIL_FAST: ${env.FAIL_FAST}"
enableDbMigration(product)
loadVaultSecrets(secrets)
enableSlackNotifications('#darts-builds')
syncBranchesWithMaster(branchesToSync)
disableCleanupOfHelmReleaseOnFailure()
env.INTEGRATION_TEST_LOGGING_LEVEL = "off"
afterAlways('test') {
builder.gradle('jacocoTestReport')
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/checkstyle",
reportFiles : "main.html",
reportName : "Checkstyle Main Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/checkstyle",
reportFiles : "test.html",
reportName : "Checkstyle Test Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/checkstyle",
reportFiles : "functionalTest.html",
reportName : "Checkstyle Functional Test Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/checkstyle",
reportFiles : "integrationTest.html",
reportName : "Checkstyle Integration Test Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/tests/test",
reportFiles : "index.html",
reportName : "Unit Tests Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/tests/integration",
reportFiles : "index.html",
reportName : "Integration Tests Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/pmd",
reportFiles : "main.html",
reportName : "PMD Main Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/pmd",
reportFiles : "test.html",
reportName : "PMD Test Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/pmd",
reportFiles : "functionalTest.html",
reportName : "PMD Functional Test Report"
]
publishHTML target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : "build/reports/pmd",
reportFiles : "integrationTest.html",
reportName : "PMD Integration Test Report"
]
}
afterFailure('test') {
junit testResults: '**/test-results/integration/*.xml'
}
afterAlways('akschartsinstall') {
if(params.SKIP_TESTS || params.SKIP_SONAR) {
stage('SKIP_TESTS OR SKIP_SONAR IS TRUE') {
error("Build can not fully complete when SKIP_TESTS or SKIP_SONAR is set to true")
}
}
}
before('dbmigrate:demo') {
sh("./gradlew --no-daemon --init-script init.gradle assemble")
}
before('dbmigrate:test') {
sh("./gradlew --no-daemon --init-script init.gradle assemble")
}
before('dbmigrate:ithc') {
sh("./gradlew --no-daemon --init-script init.gradle assemble")
}
before('akschartsinstall') {
onPR {
determineDevEnvironmentDeployment()
}
}
afterSuccess('akschartsinstall') {
onPR {
// restore the PR DB from staging
sh("./bin/ci/db-stg-to-pr.sh")
// run flyway migrate on PR DB
sh("./bin/ci/run-flyway-pr-db.sh")
}
}
}