diff --git a/src/job-summary.ts b/src/job-summary.ts index 5d82ba5..2c5b5fe 100644 --- a/src/job-summary.ts +++ b/src/job-summary.ts @@ -4,9 +4,11 @@ import path from 'path' import {logCachingReport, CacheListener} from './cache-reporting' interface BuildResult { - get rootProject(): string + get rootProjectName(): string + get rootProjectDir(): string get requestedTasks(): string get gradleVersion(): string + get gradleHomeDir(): string get buildFailed(): boolean get buildScanUri(): string } @@ -50,7 +52,7 @@ function writeSummaryTable(results: BuildResult[]): void { {data: 'Outcome', header: true} ], ...results.map(result => [ - result.rootProject, + result.rootProjectName, result.requestedTasks, result.gradleVersion, renderOutcome(result) diff --git a/src/resources/build-result-capture-service.plugin.groovy b/src/resources/build-result-capture-service.plugin.groovy index e4a29a1..2d6482f 100644 --- a/src/resources/build-result-capture-service.plugin.groovy +++ b/src/resources/build-result-capture-service.plugin.groovy @@ -6,8 +6,10 @@ import org.gradle.util.GradleVersion // But projectsEvaluated is good enough, since the build service won't catch configuration failures anyway projectsEvaluated { def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-build-action-buildResultsRecorder", BuildResultsRecorder, { spec -> - spec.getParameters().getRootProject().set(gradle.rootProject.name) + spec.getParameters().getRootProjectName().set(gradle.rootProject.name) + spec.getParameters().getRootProjectDir().set(gradle.rootProject.rootDir.absolutePath) spec.getParameters().getRequestedTasks().set(gradle.startParameter.taskNames.join(" ")) + spec.getParameters().getGradleHomeDir().set(gradle.gradleHomeDir.absolutePath) spec.getParameters().getInvocationId().set(gradle.ext.invocationId) }) @@ -17,8 +19,10 @@ projectsEvaluated { abstract class BuildResultsRecorder implements BuildService, OperationCompletionListener, AutoCloseable { private boolean buildFailed = false interface Params extends BuildServiceParameters { - Property getRootProject() + Property getRootProjectName() + Property getRootProjectDir() Property getRequestedTasks() + Property getGradleHomeDir() Property getInvocationId() } @@ -31,9 +35,11 @@ abstract class BuildResultsRecorder implements BuildService // The `buildScanPublished` hook is the only way to capture the build scan URI. if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) { - captureUsingBuildScanPublished(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject.name, invocationId) + captureUsingBuildScanPublished(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject, invocationId) } - // We also need to add hooks in case the plugin is applied but no build scan is published + // We also need to add hooks in case the plugin is applied but no build scan is published if (useBuildService) { captureUsingBuildService(settings, invocationId) } else { @@ -30,18 +30,21 @@ if (isTopLevelBuild) { } else if (atLeastGradle3) { projectsEvaluated { gradle -> if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) { - captureUsingBuildScanPublished(gradle.rootProject.extensions["buildScan"], gradle.rootProject.name, invocationId) + captureUsingBuildScanPublished(gradle.rootProject.extensions["buildScan"], gradle.rootProject, invocationId) } - // We need to capture in buildFinished in case the plugin is applied but no build scan is published + // We need to capture in buildFinished in case the plugin is applied but no build scan is published captureUsingBuildFinished(gradle, invocationId) } } } -def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocationId) { +def captureUsingBuildScanPublished(buildScanExtension, rootProject, invocationId) { buildScanExtension.with { def requestedTasks = gradle.startParameter.taskNames.join(" ") + def rootProjectName = rootProject.name + def rootProjectDir = rootProject.projectDir.absolutePath def gradleVersion = GradleVersion.current().version + def gradleHomeDir = gradle.gradleHomeDir.absolutePath def buildFailed = false buildFinished { result -> @@ -52,10 +55,12 @@ def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocati def buildScanUri = buildScan.buildScanUri.toASCIIString() def buildResults = [ - rootProject: rootProjectName, + rootProjectName: rootProjectName, + rootProjectDir: rootProjectDir, requestedTasks: requestedTasks, - gradleVersion: gradleVersion, - buildFailed: buildFailed, + gradleVersion: gradleVersion, + gradleHomeDir: gradleHomeDir, + buildFailed: buildFailed, buildScanUri: buildScanUri ] @@ -65,7 +70,7 @@ def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocati // Overwrite any contents written by buildFinished or build service, since this result is a superset. if (buildResultsFile.exists()) { - buildResultsFile.text = groovy.json.JsonOutput.toJson(buildResults) + buildResultsFile.text = groovy.json.JsonOutput.toJson(buildResults) } else { buildResultsFile << groovy.json.JsonOutput.toJson(buildResults) } @@ -78,9 +83,11 @@ def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocati def captureUsingBuildFinished(gradle, invocationId) { gradle.buildFinished { result -> def buildResults = [ - rootProject: gradle.rootProject.name, + rootProjectName: gradle.rootProject.name, + rootProjectDir: gradle.rootProject.rootDir.absolutePath, requestedTasks: gradle.startParameter.taskNames.join(" "), - gradleVersion: GradleVersion.current().version, + gradleVersion: GradleVersion.current().version, + gradleHomeDir: gradle.gradleHomeDir.absolutePath, buildFailed: result.failure != null, buildScanUri: null ] diff --git a/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy b/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy index 6b564c3..0327800 100644 --- a/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy +++ b/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy @@ -120,9 +120,11 @@ class TestBuildResultRecorder extends BaseInitScriptTest { void assertResults(String task, TestGradleVersion testGradleVersion, boolean hasFailure, boolean hasBuildScan) { def results = new JsonSlurper().parse(buildResultFile) - assert results['rootProject'] == ROOT_PROJECT_NAME + assert results['rootProjectName'] == ROOT_PROJECT_NAME + assert results['rootProjectDir'] == testProjectDir.canonicalPath assert results['requestedTasks'] == task assert results['gradleVersion'] == testGradleVersion.gradleVersion.version + assert results['gradleHomeDir'] != null assert results['buildFailed'] == hasFailure assert results['buildScanUri'] == (hasBuildScan ? "${mockScansServer.address}s/${PUBLIC_BUILD_SCAN_ID}" : null) }