@@ -246,9 +246,9 @@ stage('Default build') {
246
246
return
247
247
}
248
248
runBuildOnNode {
249
- helper . withMavenWorkspace(mavenSettingsConfig : deploySnapshot ? helper. configuration. file. deployment. maven. settingsId : null ) {
250
- sh """ \
251
- mvn clean \
249
+ withMavenWorkspace(mavenSettingsConfig : deploySnapshot ? helper. configuration. file. deployment. maven. settingsId : null ) {
250
+ mvn """ \
251
+ clean \
252
252
--fail-at-end \
253
253
${ deploySnapshot ? "\
254
254
deploy -DdeployAtEnd=true \
@@ -277,7 +277,7 @@ stage('Non-default environments') {
277
277
environments. content. jdk. enabled. each { JdkBuildEnvironment buildEnv ->
278
278
parameters. put(buildEnv. tag, {
279
279
runBuildOnNode {
280
- helper . withMavenWorkspace {
280
+ withMavenWorkspace {
281
281
mavenNonDefaultBuild buildEnv, """ \
282
282
clean install \
283
283
"""
@@ -290,7 +290,7 @@ stage('Non-default environments') {
290
290
environments. content. wildflyTck. enabled. each { WildFlyTckBuildEnvironment buildEnv ->
291
291
parameters. put(buildEnv. tag, {
292
292
runBuildOnNode {
293
- helper . withMavenWorkspace {
293
+ withMavenWorkspace {
294
294
mavenNonDefaultBuild buildEnv, """ \
295
295
clean install \
296
296
-pl tck-runner \
@@ -305,7 +305,7 @@ stage('Non-default environments') {
305
305
environments. content. sigtest. enabled. each { SigTestBuildEnvironment buildEnv ->
306
306
parameters. put(buildEnv. tag, {
307
307
runBuildOnNode {
308
- helper . withMavenWorkspace(jdk : buildEnv. jdkTool) {
308
+ withMavenWorkspace(jdk : buildEnv. jdkTool) {
309
309
mavenNonDefaultBuild buildEnv, """ \
310
310
clean install \
311
311
-pl tck-runner \
@@ -334,7 +334,7 @@ stage('Sonar analysis') {
334
334
def sonarCredentialsId = helper. configuration. file?. sonar?. credentials
335
335
if (sonarCredentialsId) {
336
336
runBuildOnNode {
337
- helper . withMavenWorkspace {
337
+ withMavenWorkspace {
338
338
if (enableDefaultBuild && enableDefaultBuildIT) {
339
339
unstash name : " default-build-jacoco-reports"
340
340
}
@@ -537,8 +537,8 @@ void mavenNonDefaultBuild(BuildEnvironment buildEnv, String args, String project
537
537
def testSuffix = buildEnv. tag. replaceAll(' [^a-zA-Z0-9_\\ -+]+' , ' _' )
538
538
539
539
dir(projectPath) {
540
- sh """ \
541
- mvn -Dsurefire.environment=$testSuffix \
540
+ mvn """ \
541
+ -Dsurefire.environment=$testSuffix \
542
542
${ toTestJdkArg(buildEnv)} \
543
543
--fail-at-end \
544
544
$args \
@@ -578,3 +578,52 @@ String toTestJdkArg(BuildEnvironment buildEnv) {
578
578
579
579
return args
580
580
}
581
+
582
+ void withMavenWorkspace (Closure body ) {
583
+ withMavenWorkspace([:], body)
584
+ }
585
+
586
+ void withMavenWorkspace (Map args , Closure body ) {
587
+ args. put(" options" , [
588
+ // Artifacts are not needed and take up disk space
589
+ artifactsPublisher(disabled : true ),
590
+ // stdout/stderr for successful tests is not needed and takes up disk space
591
+ // we archive test results and stdout/stderr as part of the build scan anyway,
592
+ // see https://ge.hibernate.org/scans?search.rootProjectNames=Hibernate%20Validator
593
+ junitPublisher(disabled : true )
594
+ ])
595
+ helper. withMavenWorkspace(args, body)
596
+ }
597
+
598
+ void mvn (String args ) {
599
+ def develocityMainCredentialsId = helper. configuration. file?. develocity?. credentials?. main
600
+ def develocityPrCredentialsId = helper. configuration. file?. develocity?. credentials?. pr
601
+ if ( ! helper. scmSource. pullRequest && develocityMainCredentialsId ) {
602
+ // Not a PR: we can pass credentials to the build, allowing it to populate the build cache
603
+ // and to publish build scans directly.
604
+ withCredentials([string(credentialsId : develocityMainCredentialsId,
605
+ variable : ' DEVELOCITY_ACCESS_KEY' )]) {
606
+ withGradle { // withDevelocity, actually: https://plugins.jenkins.io/gradle/#plugin-content-capturing-build-scans-from-jenkins-pipeline
607
+ sh " mvn $args "
608
+ }
609
+ }
610
+ }
611
+ else if ( helper. scmSource. pullRequest && develocityPrCredentialsId ) {
612
+ // Pull request: we can't pass credentials to the build, since we'd be exposing secrets to e.g. tests.
613
+ // We do the build first, then publish the build scan separately.
614
+ tryFinally({
615
+ sh " mvn $args "
616
+ }, { // Finally
617
+ withCredentials([string(credentialsId : develocityPrCredentialsId,
618
+ variable : ' DEVELOCITY_ACCESS_KEY' )]) {
619
+ withGradle { // withDevelocity, actually: https://plugins.jenkins.io/gradle/#plugin-content-capturing-build-scans-from-jenkins-pipeline
620
+ sh ' mvn develocity:build-scan-publish-previous || true'
621
+ }
622
+ }
623
+ })
624
+ }
625
+ else {
626
+ // No Develocity credentials.
627
+ sh " mvn $args "
628
+ }
629
+ }
0 commit comments