Skip to content

Commit

Permalink
Always publish a build scan in CI (#48348)
Browse files Browse the repository at this point in the history
* Always publish a build scan in CI

This PR changes the build scan configuration to alwasy publisha  build
scan when running in our CI.

We should alkready be passing these env vars into the Vagrant VM so this
will make it produce a build scan too.

The old properties to accept build scan ToS on the public server are
thus no longer relevant and will be cleaned up from the Jenkins config
once this is merged.

* Pass env vars to vagrant VM
* Enable running in parallel in the VM
* Add job name and build nomber as custom values
  • Loading branch information
alpar-t committed Oct 23, 2019
1 parent 32c5535 commit 013b2e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
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 @@ -183,6 +184,12 @@ private static List<Object> configureVM(Project project) {
VagrantExtension vagrant = project.getExtensions().getByType(VagrantExtension.class);
vagrant.setBox(box);
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(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 @@ -4,38 +4,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
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

0 comments on commit 013b2e3

Please sign in to comment.