Skip to content

Commit 013b2e3

Browse files
committed
Always publish a build scan in CI (#48348)
* 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
1 parent 32c5535 commit 013b2e3

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/DistroTestPlugin.java

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.util.Map;
6060
import java.util.Random;
6161
import java.util.stream.Collectors;
62+
import java.util.stream.Stream;
6263

6364
import static org.elasticsearch.gradle.vagrant.VagrantMachine.convertLinuxPath;
6465
import static org.elasticsearch.gradle.vagrant.VagrantMachine.convertWindowsPath;
@@ -183,6 +184,12 @@ private static List<Object> configureVM(Project project) {
183184
VagrantExtension vagrant = project.getExtensions().getByType(VagrantExtension.class);
184185
vagrant.setBox(box);
185186
vagrant.vmEnv("PATH", convertPath(project, vagrant, gradleJdk, "/bin:$PATH", "\\bin;$Env:PATH"));
187+
// pass these along to get correct build scans
188+
if (System.getenv("JENKINS_URL") != null) {
189+
Stream.of("JOB_NAME", "JENKINS_URL", "BUILD_NUMBER", "BUILD_URL").forEach(name ->
190+
vagrant.vmEnv(name, System.getenv(name))
191+
);
192+
}
186193
vagrant.setIsWindowsVM(isWindows(project));
187194

188195
return Arrays.asList(gradleJdk);

buildSrc/src/main/java/org/elasticsearch/gradle/test/GradleDistroTestTask.java

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private List<String> getScript(boolean isWindows) {
8080
line.append(" --project-cache-dir ");
8181
line.append(isWindows ? convertWindowsPath(getProject(), cacheDir) : convertLinuxPath(getProject(), cacheDir));
8282
line.append(" -S");
83+
line.append(" --parallel");
8384
line.append(" -D'org.gradle.logging.level'=" + getProject().getGradle().getStartParameter().getLogLevel());
8485
if (testClass != null) {
8586
line.append(" --tests=");

gradle/build-scan.gradle

+28-24
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,34 @@ import org.elasticsearch.gradle.OS
44
buildScan {
55
URL jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null
66
String buildNumber = System.getenv('BUILD_NUMBER')
7+
String buildUrl = System.getenv('BUILD_URL')
78
String jobName = System.getenv('JOB_NAME')
89

910
tag OS.current().name()
11+
if (jobName) {
12+
value 'Job name', jobName
13+
}
14+
if(buildNumber) {
15+
value 'Job number', buildNumber
16+
}
1017

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

1723
// Jenkins-specific build scan metadata
1824
if (jenkinsUrl) {
1925
tag 'CI'
20-
tag System.getenv('JOB_NAME')
21-
link 'Jenkins Build', System.getenv('BUILD_URL')
22-
link 'Additional Logs',
23-
"https://console.cloud.google.com/storage/elasticsearch-ci-artifacts/jobs/${jobName}/build/${buildNumber}.tar.bz2"
24-
System.getenv('NODE_LABELS').split(' ').each {
26+
tag jobName
27+
link 'Jenkins Build', buildUrl
28+
link 'GCP Upload', "https://console.cloud.google.com/storage/elasticsearch-ci-artifacts/jobs/${jobName}/build/${buildNumber}.tar.bz2"
29+
System.getenv().getOrDefault('NODE_LABELS', '').split(' ').each {
2530
value 'Jenkins Worker Label', it
2631
}
2732

28-
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
29-
30-
// Capture changes included in this CI build except for pull request builds
31-
if (System.getenv('GIT_COMMIT') && !isPrBuild) {
32-
background {
33-
def changes = "git diff --name-only ${System.getenv('GIT_PREVIOUS_COMMIT')}..${System.getenv('GIT_COMMIT')}".execute().text.trim()
34-
value 'Git Changes', changes
35-
}
36-
}
37-
3833
// Add SCM information
34+
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
3935
if (isPrBuild) {
4036
value 'Git Commit ID', System.getenv('ghprbActualCommit')
4137
value 'Git Branch', System.getenv('ghprbTargetBranch')
@@ -44,11 +40,19 @@ buildScan {
4440
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
4541
link 'Pull Request', System.getenv('ghprbPullLink')
4642
} else {
47-
def branch = System.getenv('GIT_BRANCH').split('/').last()
48-
value 'Git Commit ID', System.getenv('GIT_COMMIT')
49-
value 'Git Branch', branch
50-
tag branch
51-
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('GIT_COMMIT')}"
43+
if (System.getenv('GIT_BRANCH')) {
44+
def branch = System.getenv('GIT_BRANCH').split('/').last()
45+
value 'Git Branch', branch
46+
tag branch
47+
}
48+
if (System.getenv('GIT_COMMIT')) {
49+
value 'Git Commit ID', System.getenv('GIT_COMMIT')
50+
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('GIT_COMMIT')}"
51+
background {
52+
def changes = "git diff --name-only ${System.getenv('GIT_PREVIOUS_COMMIT')}..${System.getenv('GIT_COMMIT')}".execute().text.trim()
53+
value 'Git Changes', changes
54+
}
55+
}
5256
}
5357
} else {
5458
tag 'LOCAL'

0 commit comments

Comments
 (0)