Skip to content

Commit 032a394

Browse files
committed
HV-2059 Add build scan publishing
1 parent 5231561 commit 032a394

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

Jenkinsfile

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ stage('Default build') {
246246
return
247247
}
248248
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 \
252252
--fail-at-end \
253253
${deploySnapshot ? "\
254254
deploy -DdeployAtEnd=true \
@@ -277,7 +277,7 @@ stage('Non-default environments') {
277277
environments.content.jdk.enabled.each { JdkBuildEnvironment buildEnv ->
278278
parameters.put(buildEnv.tag, {
279279
runBuildOnNode {
280-
helper.withMavenWorkspace {
280+
withMavenWorkspace {
281281
mavenNonDefaultBuild buildEnv, """ \
282282
clean install \
283283
"""
@@ -290,7 +290,7 @@ stage('Non-default environments') {
290290
environments.content.wildflyTck.enabled.each { WildFlyTckBuildEnvironment buildEnv ->
291291
parameters.put(buildEnv.tag, {
292292
runBuildOnNode {
293-
helper.withMavenWorkspace {
293+
withMavenWorkspace {
294294
mavenNonDefaultBuild buildEnv, """ \
295295
clean install \
296296
-pl tck-runner \
@@ -305,7 +305,7 @@ stage('Non-default environments') {
305305
environments.content.sigtest.enabled.each { SigTestBuildEnvironment buildEnv ->
306306
parameters.put(buildEnv.tag, {
307307
runBuildOnNode {
308-
helper.withMavenWorkspace(jdk: buildEnv.jdkTool) {
308+
withMavenWorkspace(jdk: buildEnv.jdkTool) {
309309
mavenNonDefaultBuild buildEnv, """ \
310310
clean install \
311311
-pl tck-runner \
@@ -334,7 +334,7 @@ stage('Sonar analysis') {
334334
def sonarCredentialsId = helper.configuration.file?.sonar?.credentials
335335
if (sonarCredentialsId) {
336336
runBuildOnNode {
337-
helper.withMavenWorkspace {
337+
withMavenWorkspace {
338338
if (enableDefaultBuild && enableDefaultBuildIT) {
339339
unstash name: "default-build-jacoco-reports"
340340
}
@@ -537,8 +537,8 @@ void mavenNonDefaultBuild(BuildEnvironment buildEnv, String args, String project
537537
def testSuffix = buildEnv.tag.replaceAll('[^a-zA-Z0-9_\\-+]+', '_')
538538

539539
dir(projectPath) {
540-
sh """ \
541-
mvn -Dsurefire.environment=$testSuffix \
540+
mvn """ \
541+
-Dsurefire.environment=$testSuffix \
542542
${toTestJdkArg(buildEnv)} \
543543
--fail-at-end \
544544
$args \
@@ -578,3 +578,52 @@ String toTestJdkArg(BuildEnvironment buildEnv) {
578578

579579
return args
580580
}
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

Comments
 (0)