Skip to content

Always publish a build scan in CI #48348

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 6 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.elasticsearch.gradle.vagrant.VagrantMachine.convertLinuxPath;
import static org.elasticsearch.gradle.vagrant.VagrantMachine.convertWindowsPath;
Expand Down Expand Up @@ -187,6 +188,12 @@ private static List<Object> configureVM(Project project) {
vagrant.setBox(box);
vagrant.vmEnv("SYSTEM_JAVA_HOME", convertPath(project, vagrant, systemJdk, "", ""));
vagrant.vmEnv("PATH", convertPath(project, vagrant, gradleJdk, "/bin:$PATH", "\\bin;$Env:PATH"));
// pass these along to get correct build scans
if (System.getenv("JENKINS_URL") != null) {
Stream.of("JOB_NAME", "JENKINS_URL", "BUILD_NUMBER", "BUILD_URL").forEach(name ->
vagrant.vmEnv(name, System.getenv(name))
);
}
vagrant.setIsWindowsVM(isWindows(project));

return Arrays.asList(systemJdk, gradleJdk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private List<String> getScript(boolean isWindows) {
line.append(" --project-cache-dir ");
line.append(isWindows ? convertWindowsPath(getProject(), cacheDir) : convertLinuxPath(getProject(), cacheDir));
line.append(" -S");
line.append(" --parallel");
line.append(" -D'org.gradle.logging.level'=" + getProject().getGradle().getStartParameter().getLogLevel());
if (testClass != null) {
line.append(" --tests=");
Expand Down
52 changes: 28 additions & 24 deletions gradle/build-scan.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,34 @@ import org.elasticsearch.gradle.OS
buildScan {
URL jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null
String buildNumber = System.getenv('BUILD_NUMBER')
String buildUrl = System.getenv('BUILD_URL')
String jobName = System.getenv('JOB_NAME')

tag OS.current().name()
if (jobName) {
value 'Job name', jobName
}
if(buildNumber) {
value 'Job number', buildNumber
}

// Accept Gradle ToS when project property org.elasticsearch.acceptScanTOS=true or this is an Elastic CI build
if (jenkinsUrl?.host?.endsWith('elastic.co') || Boolean.valueOf(project.findProperty('org.elasticsearch.acceptScanTOS') ?: "false")) {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
if (jenkinsUrl?.host?.endsWith('elastic.co')) {
publishAlways()
buildScan.server = 'https://gradle-enterprise.elastic.co'
}

// Jenkins-specific build scan metadata
if (jenkinsUrl) {
tag 'CI'
tag System.getenv('JOB_NAME')
link 'Jenkins Build', System.getenv('BUILD_URL')
link 'Additional Logs',
"https://console.cloud.google.com/storage/elasticsearch-ci-artifacts/jobs/${jobName}/build/${buildNumber}.tar.bz2"
System.getenv('NODE_LABELS').split(' ').each {
tag jobName
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should add the build number as a custom value as well, that way we could search for all scans for a given job? Or even the URL itself as a custom value would serve the same purpose, as right now you can search on links.

link 'Jenkins Build', buildUrl
link 'GCP Upload', "https://console.cloud.google.com/storage/elasticsearch-ci-artifacts/jobs/${jobName}/build/${buildNumber}.tar.bz2"
System.getenv().getOrDefault('NODE_LABELS', '').split(' ').each {
value 'Jenkins Worker Label', it
}

def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null

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

// Add SCM information
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
if (isPrBuild) {
value 'Git Commit ID', System.getenv('ghprbActualCommit')
value 'Git Branch', System.getenv('ghprbTargetBranch')
Expand All @@ -44,11 +40,19 @@ buildScan {
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
link 'Pull Request', System.getenv('ghprbPullLink')
} else {
def branch = System.getenv('GIT_BRANCH').split('/').last()
value 'Git Commit ID', System.getenv('GIT_COMMIT')
value 'Git Branch', branch
tag branch
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('GIT_COMMIT')}"
if (System.getenv('GIT_BRANCH')) {
def branch = System.getenv('GIT_BRANCH').split('/').last()
value 'Git Branch', branch
tag branch
}
if (System.getenv('GIT_COMMIT')) {
value 'Git Commit ID', System.getenv('GIT_COMMIT')
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('GIT_COMMIT')}"
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'
Expand Down