/
Jenkinsfile
699 lines (641 loc) · 25.7 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
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
import groovy.transform.Field
import org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException
/*
* See https://github.com/hibernate/hibernate-jenkins-pipeline-helpers
*/
@Library('hibernate-jenkins-pipeline-helpers@1.2')
import org.hibernate.jenkins.pipeline.helpers.job.JobHelper
import org.hibernate.jenkins.pipeline.helpers.alternative.AlternativeMultiMap
import org.hibernate.jenkins.pipeline.helpers.version.Version
/*
* WARNING: DO NOT IMPORT LOCAL LIBRARIES HERE.
*
* By local, I mean libraries whose files are in the same Git repository.
*
* The Jenkinsfile is protected and will not be executed if modified in pull requests from external users,
* but other local library files are not protected.
* A user could potentially craft a malicious PR by modifying a local library.
*
* See https://blog.grdryn.me/blog/jenkins-pipeline-trust.html for a full explanation,
* and a potential solution if we really need local libraries.
* Alternatively we might be able to host libraries in a separate GitHub repo and configure
* them in the GUI: see https://ci.hibernate.org/job/hibernate-search/configure, "Pipeline Libraries".
*/
/*
* See https://github.com/hibernate/hibernate-jenkins-pipeline-helpers for the documentation
* of the helpers library used in this Jenkinsfile,
* and for help writing Jenkinsfiles.
*
* ### Jenkins configuration
*
* #### Jenkins plugins
*
* This file requires the following plugins in particular:
*
* - everything required by the helpers library (see the org.hibernate.(...) imports for a link to its documentation)
* - https://plugins.jenkins.io/ec2 for AWS credentials
* - https://plugins.jenkins.io/lockable-resources for the lock on the AWS Elasticsearch server
* - https://plugins.jenkins.io/pipeline-github for the trigger on pull request comments
*
* #### Script approval
*
* If not already done, you will need to allow the following calls in <jenkinsUrl>/scriptApproval/:
*
* - everything required by the helpers library (see the org.hibernate.(...) imports for a link to its documentation)
*
* ### Integrations
*
* #### Nexus deployment
*
* This job includes two deployment modes:
*
* - A deployment of snapshot artifacts for every non-PR build on "primary" branches (master and maintenance branches).
* - A full release when starting the job with specific parameters.
*
* In the first case, the name of a Maven settings file must be provided in the job configuration file
* (see below).
*
* #### Coveralls (optional)
*
* You need to enable your repository in Coveralls first: see https://coveralls.io/repos/new.
*
* Then you will also need to add the Coveralls repository token as credentials in Jenkins
* (see "Credentials" section below).
*
* #### Gitter (optional)
*
* You need to enable the Jenkins integration in your Gitter room first:
* see https://gitlab.com/gitlab-org/gitter/webapp/blob/master/docs/integrations.md
*
* Then you will also need to configure *global* secret text credentials containing the Gitter webhook URL,
* and list the ID of these credentials in the job configuration file
* (see https://github.com/hibernate/hibernate-jenkins-pipeline-helpers#job-configuration-file).
*
* ### Job configuration
*
* This Jenkinsfile gets its configuration from four sources:
* branch name, environment variables, a configuration file, and credentials.
* All configuration is optional for the default build (and it should stay that way),
* but some features require some configuration.
*
* #### Branch name
*
* See the org.hibernate.(...) imports for a link to the helpers library documentation,
* which explains the basics.
*
* #### Environment variables
*
* The following environment variables are necessary for some features:
*
* - 'ES_AWS_REGION', containing the name of an AWS region such as 'us-east-1', to test Elasticsearch as a service on AWS.
* - 'ES_AWS_<majorminor without dot>_ENDPOINT' (e.g. 'ES_AWS_52_ENDPOINT'),
* containing the URL of an AWS Elasticsearch service endpoint using that exact version,
* to test Elasticsearch as a service on AWS.
*
* #### Job configuration file
*
* See the org.hibernate.(...) imports for a link to the helpers library documentation,
* which explains the basic structure of this file and how to set it up.
*
* Below is the additional structure specific to this Jenkinsfile:
*
* deployment:
* maven:
* # String containing the ID of a Maven settings file registered using the config-file-provider Jenkins plugin.
* # The settings must provide credentials to the servers with ID
* # 'jboss-releases-repository' and 'jboss-snapshots-repository'.
* settingsId: ...
*
* #### Credentials
*
* The following credentials are necessary for some features:
*
* - 'aws-elasticsearch' AWS credentials, to test Elasticsearch as a service on AWS
* - 'coveralls-repository-token' secret text credentials containing the repository token,
* to send coverage reports to coveralls.io. Note these credentials should be registered at the job level, not system-wide.
*/
@Field final String MAVEN_TOOL = 'Apache Maven 3.6'
// Default node pattern, to be used for resource-intensive stages.
// Should not include the master node.
@Field final String NODE_PATTERN_BASE = 'Slave'
// Quick-use node pattern, to be used for very light, quick, and environment-independent stages,
// such as sending a notification. May include the master node in particular.
@Field final String QUICK_USE_NODE_PATTERN = 'Master||Slave'
@Field AlternativeMultiMap<BuildEnvironment> environments
@Field JobHelper helper
@Field boolean enableDefaultBuild = false
@Field boolean enableDefaultBuildIT = false
@Field boolean performRelease = false
@Field boolean deploySnapshot = false
@Field Version releaseVersion
@Field Version afterReleaseDevelopmentVersion
this.helper = new JobHelper(this)
helper.runWithNotification {
stage('Configure') {
this.environments = AlternativeMultiMap.create([
jdk: [
// This should not include every JDK; in particular let's not care too much about EOL'd JDKs like version 9
// See http://www.oracle.com/technetwork/java/javase/eol-135779.html
new JdkBuildEnvironment(version: '8', tool: 'OpenJDK 8 Latest', status: BuildEnvironmentStatus.USED_IN_DEFAULT_BUILD),
new JdkBuildEnvironment(version: '11', tool: 'OpenJDK 11 Latest', status: BuildEnvironmentStatus.SUPPORTED),
new JdkBuildEnvironment(version: '12', tool: 'OpenJDK 12 Latest', status: BuildEnvironmentStatus.SUPPORTED),
new JdkBuildEnvironment(version: '13', tool: 'OpenJDK 13 Latest', status: BuildEnvironmentStatus.EXPERIMENTAL,
// Elasticsearch won't run on JDK13+
elasticsearchTool: 'OpenJDK 11 Latest'),
new JdkBuildEnvironment(version: '14', tool: 'OpenJDK 14 Latest', status: BuildEnvironmentStatus.EXPERIMENTAL,
// Elasticsearch won't run on JDK13+
elasticsearchTool: 'OpenJDK 11 Latest')
],
compiler: [
new CompilerBuildEnvironment(name: 'eclipse', mavenProfile: 'compiler-eclipse', status: BuildEnvironmentStatus.SUPPORTED),
],
database: [
new DatabaseBuildEnvironment(dbName: 'h2', mavenProfile: 'h2', status: BuildEnvironmentStatus.USED_IN_DEFAULT_BUILD),
new DatabaseBuildEnvironment(dbName: 'mariadb', mavenProfile: 'ci-mariadb', status: BuildEnvironmentStatus.SUPPORTED),
new DatabaseBuildEnvironment(dbName: 'postgresql', mavenProfile: 'ci-postgresql', status: BuildEnvironmentStatus.SUPPORTED)
],
esLocal: [
new EsLocalBuildEnvironment(versionRange: '[2.0,2.2)', mavenProfile: 'elasticsearch-2.0', status: BuildEnvironmentStatus.SUPPORTED),
new EsLocalBuildEnvironment(versionRange: '[2.2,5.0)', mavenProfile: 'elasticsearch-2.2', status: BuildEnvironmentStatus.SUPPORTED),
// Use Elasticsearch 5.0.2 instead of the default 5.1.2, because a bug crashes ES on startup in our environment
// See https://github.com/elastic/elasticsearch/issues/23218
new EsLocalBuildEnvironment(versionRange: '[5.0,5.2)', version: '5.0.2', mavenProfile: 'elasticsearch-5.0', status: BuildEnvironmentStatus.SUPPORTED),
new EsLocalBuildEnvironment(versionRange: '[5.2,6.0)', mavenProfile: 'elasticsearch-5.2', status: BuildEnvironmentStatus.USED_IN_DEFAULT_BUILD)
],
esAws: [
new EsAwsBuildEnvironment(version: '2.3', mavenProfile: 'elasticsearch-2.2', status: BuildEnvironmentStatus.SUPPORTED),
new EsAwsBuildEnvironment(version: '5.1', mavenProfile: 'elasticsearch-5.0', status: BuildEnvironmentStatus.SUPPORTED),
new EsAwsBuildEnvironment(version: '5.3', mavenProfile: 'elasticsearch-5.2', status: BuildEnvironmentStatus.SUPPORTED),
new EsAwsBuildEnvironment(version: '5.5', mavenProfile: 'elasticsearch-5.2', status: BuildEnvironmentStatus.SUPPORTED),
new EsAwsBuildEnvironment(version: '5.6', mavenProfile: 'elasticsearch-5.2', status: BuildEnvironmentStatus.SUPPORTED)
]
])
helper.configure {
configurationNodePattern QUICK_USE_NODE_PATTERN
file 'job-configuration.yaml'
jdk {
defaultTool environments.content.jdk.default.tool
}
maven {
defaultTool MAVEN_TOOL
producedArtifactPattern "org/hibernate/hibernate-search*"
}
}
properties([
buildDiscarder(
logRotator(daysToKeepStr: '90')
),
pipelineTriggers(
// HSEARCH-3417: do not add snapshotDependencies() here, this was known to cause problems.
[
issueCommentTrigger('.*test this please.*')
]
+ helper.generateUpstreamTriggers()
),
helper.generateNotificationProperty(),
parameters([
choice(
name: 'ENVIRONMENT_SET',
choices: """AUTOMATIC
DEFAULT
SUPPORTED
EXPERIMENTAL
ALL""",
defaultValue: 'AUTOMATIC',
description: """A set of environments that must be checked.
'AUTOMATIC' picks a different set of environments based on the branch name and whether a release is being performed.
'DEFAULT' means a single build with the default environment expected by the Maven configuration,
while other options will trigger multiple Maven executions in different environments."""
),
string(
name: 'ENVIRONMENT_FILTER',
defaultValue: '',
trim: true,
description: """A regex filter to apply to the environments that must be checked.
If this parameter is non-empty, ENVIRONMENT_SET will be ignored and environments whose tag matches the given regex will be checked.
Some useful filters: 'default', 'jdk', 'jdk-10', 'eclipse', 'postgresql', 'elasticsearch-local-[5.6'.
"""
),
string(
name: 'RELEASE_VERSION',
defaultValue: '',
description: 'The version to be released, e.g. 5.10.0.Final. Setting this triggers a release.',
trim: true
),
string(
name: 'RELEASE_DEVELOPMENT_VERSION',
defaultValue: '',
description: 'The next version to be used after the release, e.g. 5.10.0-SNAPSHOT.',
trim: true
),
booleanParam(
name: 'RELEASE_DRY_RUN',
defaultValue: false,
description: 'If true, just simulate the release, without pushing any commits or tags, and without uploading any artifacts or documentation.'
)
])
])
performRelease = (params.RELEASE_VERSION ? true : false)
if (!performRelease && helper.scmSource.branch.primary && !helper.scmSource.pullRequest) {
if (helper.configuration.file?.deployment?.maven?.settingsId) {
deploySnapshot = true
}
else {
echo "Missing deployment configuration in job configuration file - snapshot deployment will be skipped."
}
}
if (params.ENVIRONMENT_FILTER) {
keepOnlyEnvironmentsMatchingFilter(params.ENVIRONMENT_FILTER)
}
else {
keepOnlyEnvironmentsFromSet(params.ENVIRONMENT_SET)
}
environments.content.esAws.enabled.removeAll { buildEnv ->
buildEnv.endpointUrl = env.getProperty(buildEnv.endpointVariableName)
if (!buildEnv.endpointUrl) {
echo "Skipping test ${buildEnv.tag} because environment variable '${buildEnv.endpointVariableName}' is not defined."
return true
}
buildEnv.awsRegion = env.ES_AWS_REGION
if (!buildEnv.awsRegion) {
echo "Skipping test ${buildEnv.tag} because environment variable 'ES_AWS_REGION' is not defined."
return true
}
return false // Environment is fully defined, do not remove
}
// Determine whether ITs need to be run in the default build
enableDefaultBuildIT = environments.content.any { key, envSet ->
return envSet.enabled.contains(envSet.default)
}
// No need to re-test default environments separately, they will be tested as part of the default build if needed
environments.content.each { key, envSet ->
envSet.enabled.remove(envSet.default)
}
enableDefaultBuild =
enableDefaultBuildIT ||
environments.content.any { key, envSet -> envSet.enabled.any { buildEnv -> buildEnv.requiresDefaultBuildArtifacts() } } ||
deploySnapshot
echo """Branch: ${helper.scmSource.branch.name}
PR: ${helper.scmSource.pullRequest?.id}
params.ENVIRONMENT_SET: ${params.ENVIRONMENT_SET}
params.ENVIRONMENT_FILTER: ${params.ENVIRONMENT_FILTER}
Resulting execution plan:
enableDefaultBuild=$enableDefaultBuild
enableDefaultBuildIT=$enableDefaultBuildIT
environments=${environments.enabledAsString}
performRelease=$performRelease
deploySnapshot=$deploySnapshot
"""
if (performRelease) {
releaseVersion = Version.parseReleaseVersion(params.RELEASE_VERSION)
echo "Inferred version family for the release to '$releaseVersion.family'"
// Check that all the necessary parameters are set
if (!params.RELEASE_DEVELOPMENT_VERSION) {
throw new IllegalArgumentException(
"Missing value for parameter RELEASE_DEVELOPMENT_VERSION." +
" This parameter must be set when RELEASE_VERSION is set."
)
}
if (!params.RELEASE_DRY_RUN && !helper.configuration.file?.deployment?.maven?.settingsId) {
throw new IllegalArgumentException(
"Missing deployment configuration in job configuration file." +
" Cannot deploy artifacts during the release."
)
}
}
if (params.RELEASE_DEVELOPMENT_VERSION) {
afterReleaseDevelopmentVersion = Version.parseDevelopmentVersion(params.RELEASE_DEVELOPMENT_VERSION)
}
}
stage('Default build') {
if (!enableDefaultBuild) {
echo 'Skipping default build and integration tests in the default environment'
helper.markStageSkipped()
return
}
node(NODE_PATTERN_BASE) {
helper.withMavenWorkspace {
sh """ \
mvn clean install \
-Pdist -Pcoverage -Pjqassistant \
${enableDefaultBuildIT ? '' : '-DskipITs'} \
"""
// Don't try to report to Coveralls.io or SonarCloud if coverage data is missing
if (enableDefaultBuildIT) {
try {
withCredentials([string(credentialsId: 'coveralls-repository-token', variable: 'COVERALLS_TOKEN')]) {
sh """ \
mvn coveralls:report \
-DrepoToken=${COVERALLS_TOKEN} \
${helper.scmSource.pullRequest ? """ \
-DpullRequest=${helper.scmSource.pullRequest.id} \
""" : """ \
-Dbranch=${helper.scmSource.branch.name} \
"""} \
"""
}
}
catch (CredentialNotFoundException e) {
echo "No Coveralls token configured - skipping Coveralls report. Error was: ${e}"
}
}
dir(helper.configuration.maven.localRepositoryPath) {
stash name:'main-build', includes:"org/hibernate/hibernate-search*/**"
}
}
}
}
stage('Non-default environments') {
Map<String, Closure> executions = [:]
// Test with multiple JDKs
environments.content.jdk.enabled.each { JdkBuildEnvironment buildEnv ->
executions.put(buildEnv.tag, {
node(NODE_PATTERN_BASE) {
def elasticsearchJdkTool = buildEnv.elasticsearchTool ? tool(name: buildEnv.elasticsearchTool, type: 'jdk') : null
helper.withMavenWorkspace(jdk: buildEnv.tool) {
mavenNonDefaultBuild buildEnv, """ \
clean install --fail-at-end \
${elasticsearchJdkTool ? "-Dtest.elasticsearch.java_home=$elasticsearchJdkTool" : ""} \
"""
}
}
})
}
// Build with different compilers
environments.content.compiler.enabled.each { CompilerBuildEnvironment buildEnv ->
executions.put(buildEnv.tag, {
node(NODE_PATTERN_BASE) {
helper.withMavenWorkspace {
mavenNonDefaultBuild buildEnv, """ \
clean install --fail-at-end \
-DskipTests \
-P${buildEnv.mavenProfile} \
"""
}
}
})
}
// Test ORM integration with multiple databases
environments.content.database.enabled.each { DatabaseBuildEnvironment buildEnv ->
executions.put(buildEnv.tag, {
node(NODE_PATTERN_BASE) {
helper.withMavenWorkspace {
mavenNonDefaultBuild buildEnv, """ \
clean install -pl org.hibernate:hibernate-search-orm -P$buildEnv.mavenProfile \
"""
}
}
})
}
// Test Elasticsearch integration with multiple versions in a local instance
environments.content.esLocal.enabled.each { EsLocalBuildEnvironment buildEnv ->
executions.put(buildEnv.tag, {
node(NODE_PATTERN_BASE) {
helper.withMavenWorkspace {
mavenNonDefaultBuild buildEnv, """ \
clean install -pl org.hibernate:hibernate-search-integrationtest-elasticsearch \
${toMavenElasticsearchProfileArg(buildEnv.mavenProfile)} \
${buildEnv.version ? "-Dtest.elasticsearch.host.version=$buildEnv.version" : ''} \
"""
}
}
})
}
// Test Elasticsearch integration with multiple versions in an AWS instance
environments.content.esAws.enabled.each { EsAwsBuildEnvironment buildEnv ->
if (!buildEnv.endpointUrl) {
throw new IllegalStateException("Unexpected empty endpoint URL")
}
if (!buildEnv.awsRegion) {
throw new IllegalStateException("Unexpected empty AWS region")
}
executions.put(buildEnv.tag, {
lock(label: buildEnv.lockedResourcesLabel) {
node(NODE_PATTERN_BASE + '&&AWS') {
helper.withMavenWorkspace {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
credentialsId : 'aws-elasticsearch',
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY'
]]) {
mavenNonDefaultBuild buildEnv, """ \
clean install -pl org.hibernate:hibernate-search-integrationtest-elasticsearch \
${toMavenElasticsearchProfileArg(buildEnv.mavenProfile)} \
-Dtest.elasticsearch.host.provided=true \
-Dtest.elasticsearch.host.url=$buildEnv.endpointUrl \
-Dtest.elasticsearch.host.aws.signing.enabled=true \
-Dtest.elasticsearch.host.aws.access_key=$AWS_ACCESS_KEY_ID \
-Dtest.elasticsearch.host.aws.secret_key=$AWS_SECRET_ACCESS_KEY \
-Dtest.elasticsearch.host.aws.region=$buildEnv.awsRegion \
"""
}
}
}
}
})
}
if (executions.isEmpty()) {
echo 'Skipping builds in non-default environments'
helper.markStageSkipped()
}
else {
parallel(executions)
}
}
stage('Deploy') {
if (deploySnapshot) {
echo "Deploying snapshots"
node(NODE_PATTERN_BASE) {
helper.withMavenWorkspace(mavenSettingsConfig: helper.configuration.file.deployment.maven.settingsId) {
sh "mvn clean deploy -Pdist -DskipTests"
}
}
}
else if (performRelease) {
echo "Performing full release for version ${releaseVersion.toString()}"
node(NODE_PATTERN_BASE) {
helper.withMavenWorkspace(mavenSettingsConfig: params.RELEASE_DRY_RUN ? null : helper.configuration.file.deployment.maven.settingsId) {
sh "git clone https://github.com/hibernate/hibernate-noorm-release-scripts.git"
sh "bash -xe hibernate-noorm-release-scripts/prepare-release.sh search ${releaseVersion.toString()}"
String deployCommand = "bash -xe hibernate-noorm-release-scripts/deploy.sh search"
if (!params.RELEASE_DRY_RUN) {
sh deployCommand
} else {
echo "WARNING: Not deploying. Would have executed:"
echo deployCommand
}
String uploadDistributionCommand = "bash -xe hibernate-noorm-release-scripts/upload-distribution.sh search ${releaseVersion.toString()}"
String uploadDocumentationCommand = "bash -xe hibernate-noorm-release-scripts/upload-documentation.sh search ${releaseVersion.toString()} ${releaseVersion.family}"
if (!params.RELEASE_DRY_RUN) {
sh uploadDistributionCommand
sh uploadDocumentationCommand
}
else {
echo "WARNING: Not uploading anything. Would have executed:"
echo uploadDistributionCommand
echo uploadDocumentationCommand
}
sh "bash -xe hibernate-noorm-release-scripts/update-version.sh search ${afterReleaseDevelopmentVersion.toString()}"
sh "bash -xe hibernate-noorm-release-scripts/push-upstream.sh search ${releaseVersion.toString()} ${helper.scmSource.branch.name} ${!params.RELEASE_DRY_RUN}"
}
}
}
else {
echo "Skipping deployment"
helper.markStageSkipped()
return
}
}
} // End of helper.runWithNotification
// Job-specific helpers
enum BuildEnvironmentStatus {
// For environments used as part of the default build (tested on all branches)
USED_IN_DEFAULT_BUILD,
// For environments that are expected to work correctly (tested on master and maintenance branches)
SUPPORTED,
// For environments that may not work correctly (only tested when explicitly requested through job parameters)
EXPERIMENTAL;
// Work around JENKINS-33023
// See https://issues.jenkins-ci.org/browse/JENKINS-33023?focusedCommentId=325738&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-325738
public BuildEnvironmentStatus() {}
}
abstract class BuildEnvironment {
BuildEnvironmentStatus status
String toString() { getTag() }
abstract String getTag()
boolean isDefault() { status == BuildEnvironmentStatus.USED_IN_DEFAULT_BUILD }
boolean requiresDefaultBuildArtifacts() { true }
}
class JdkBuildEnvironment extends BuildEnvironment {
String version
String tool
String elasticsearchTool
String getTag() { "jdk-$version" }
@Override
boolean requiresDefaultBuildArtifacts() { false }
}
class CompilerBuildEnvironment extends BuildEnvironment {
String name
String mavenProfile
String getTag() { "compiler-$name" }
@Override
boolean requiresDefaultBuildArtifacts() { false }
}
class DatabaseBuildEnvironment extends BuildEnvironment {
String dbName
String mavenProfile
String getTag() { "database-$dbName" }
}
class EsLocalBuildEnvironment extends BuildEnvironment {
String versionRange
String version
String mavenProfile
String getTag() { "elasticsearch-local-$versionRange${version ? "-as-$version" : ''}" }
}
class EsAwsBuildEnvironment extends BuildEnvironment {
String version
String mavenProfile
String endpointUrl = null
String awsRegion = null
String getTag() { "elasticsearch-aws-$version" }
String getNameEmbeddableVersion() {
version.replaceAll('\\.', '')
}
String getEndpointVariableName() {
"ES_AWS_${nameEmbeddableVersion}_ENDPOINT"
}
String getLockedResourcesLabel() {
"es-aws-${nameEmbeddableVersion}"
}
}
void keepOnlyEnvironmentsMatchingFilter(String regex) {
def pattern = /$regex/
boolean enableDefault = ('default' =~ pattern)
environments.content.each { key, envSet ->
envSet.enabled.removeAll { buildEnv ->
!(buildEnv.tag =~ pattern) && !(envSet.default == buildEnv && enableDefault)
}
}
}
void keepOnlyEnvironmentsFromSet(String environmentSetName) {
boolean enableDefaultBuildEnv = false
boolean enableNonDefaultSupportedBuildEnv = false
boolean enableExperimentalBuildEnv = false
switch (environmentSetName) {
case 'DEFAULT':
enableDefaultBuildEnv = true
break
case 'SUPPORTED':
enableDefaultBuildEnv = true
enableNonDefaultSupportedBuildEnv = true
break
case 'ALL':
enableDefaultBuildEnv = true
enableNonDefaultSupportedBuildEnv = true
enableExperimentalBuildEnv = true
break
case 'EXPERIMENTAL':
enableExperimentalBuildEnv = true
break
case 'AUTOMATIC':
if (params.RELEASE_VERSION) {
echo "Skipping default build and integration tests to speed up the release of version $params.RELEASE_VERSION"
} else if (helper.scmSource.pullRequest) {
echo "Enabling only the default build in the default environment for pull request $helper.scmSource.pullRequest.id"
enableDefaultBuildEnv = true
} else if (helper.scmSource.branch.primary) {
echo "Enabling builds on all supported environments for primary branch '$helper.scmSource.branch.name'"
enableDefaultBuildEnv = true
enableNonDefaultSupportedBuildEnv = true
} else {
echo "Enabling only the default build in the default environment for feature branch $helper.scmSource.branch.name"
enableDefaultBuildEnv = true
}
break
default:
throw new IllegalArgumentException(
"Unknown value for param 'ENVIRONMENT_SET': '$environmentSetName'."
)
}
// Filter environments
environments.content.each { key, envSet ->
if (!enableDefaultBuildEnv) {
envSet.enabled.remove(envSet.default)
}
if (!enableNonDefaultSupportedBuildEnv) {
envSet.enabled.removeAll { buildEnv -> buildEnv.status == BuildEnvironmentStatus.SUPPORTED }
}
if (!enableExperimentalBuildEnv) {
envSet.enabled.removeAll { buildEnv -> buildEnv.status == BuildEnvironmentStatus.EXPERIMENTAL }
}
}
}
void mavenNonDefaultBuild(BuildEnvironment buildEnv, String args) {
if ( buildEnv.requiresDefaultBuildArtifacts() ) {
dir(helper.configuration.maven.localRepositoryPath) {
unstash name:'main-build'
}
}
// Add a suffix to tests to distinguish between different executions
// of the same test in different environments in reports
def testSuffix = buildEnv.tag.replaceAll('[^a-zA-Z0-9_\\-+]+', '_')
sh "mvn -Dsurefire.environment=$testSuffix $args"
}
String toMavenElasticsearchProfileArg(String mavenEsProfile) {
String defaultEsProfile = environments.content.esLocal.default.mavenProfile
if (mavenEsProfile != defaultEsProfile) {
// Disable the default profile to avoid conflicting configurations
"-P!$defaultEsProfile,$mavenEsProfile"
}
else {
// Do not do as above, as we would tell Maven "disable the default profile, but enable it"
// and Maven would end up disabling it.
''
}
}