Skip to content

Improve build scan metadata #44247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ import org.gradle.util.DistributionLocator
import org.gradle.plugins.ide.eclipse.model.SourceFolder

plugins {
id 'com.gradle.build-scan' version '2.2.1'
id 'com.gradle.build-scan' version '2.3'
id 'base'
id 'elasticsearch.global-build-info'
}
if (Boolean.valueOf(project.findProperty('org.elasticsearch.acceptScanTOS') ?: "false")) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}

apply plugin: 'nebula.info-scm'
apply from: 'gradle/build-scan.gradle'

// common maven publishing configuration
allprojects {
Expand All @@ -49,7 +46,6 @@ allprojects {

BuildPlugin.configureRepositories(project)

apply plugin: 'nebula.info-scm'
String licenseCommit
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
licenseCommit = scminfo.change ?: "master" // leniency for non git builds
Expand Down
38 changes: 38 additions & 0 deletions gradle/build-scan.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import nebula.plugin.info.scm.ScmInfoExtension

buildScan {
// Accept Gradle ToS when project property org.elasticsearch.acceptScanTOS=true
if (Boolean.valueOf(project.findProperty('org.elasticsearch.acceptScanTOS') ?: "false")) {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}

// Jenkins-specific build scan metadata
if (System.getenv('JENKINS_URL')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check if this contains elastic.co to make sure it's our CI and accept the terms of service if so so no additional property needs to be passed in Jenkins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we'll be pushing scans to Gradle Enterprise which doesn't require accepting the ToS so I think that might be unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone ahead and implemented this. I agree, it'd be nice to ditch the need to pass the ToS param in Jenkins for the time being.

tag 'CI'
tag System.getenv('JOB_NAME')
link 'Jenkins Build', System.getenv('BUILD_URL')

// Capture changes included in this CI build except for pull request builds
if (System.getenv('GIT_COMMIT') && System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') == null) {
background {
def changes = "git diff --name-only ${System.getenv('GIT_PREVIOUS_COMMIT')}..${System.getenv('GIT_COMMIT')}".execute().text.trim()
value 'Git Changes', changes
}
}
} else {
tag 'LOCAL'
}

// Add SCM information
def scmInfo = project.extensions.findByType(ScmInfoExtension)
if (scmInfo && scmInfo.change && scmInfo.branch) {
value 'Git Commit ID', scmInfo.change
// Don't tag the branch if we are in a detached head state
if (scmInfo.branch ==~ /[0-9a-f]{5,40}/ == false) {
value 'Git Branch', scmInfo.branch
tag scmInfo.branch
}
link 'Source', "https://github.com/elastic/elasticsearch/commit/${scmInfo.change}"
}
}