Skip to content

Commit 7ddbaa2

Browse files
authored
[Gradle] Simplify Build Scan setup (#112347)
- remove jenkins specific logic - more simplification on build scan build logic
1 parent 436c1da commit 7ddbaa2

File tree

1 file changed

+9
-70
lines changed

1 file changed

+9
-70
lines changed

build-tools-internal/src/main/groovy/elasticsearch.build-scan.gradle

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ import java.time.LocalDateTime
1919
develocity {
2020

2121
buildScan {
22-
URL jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null
23-
String buildKiteUrl = System.getenv('BUILDKITE_BUILD_URL') ? System.getenv('BUILDKITE_BUILD_URL') : null
22+
23+
def onCI = System.getenv('CI') ? Boolean.parseBoolean(System.getenv('CI')) : false
24+
25+
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
26+
uploadInBackground = onCI == false
2427

2528
// Automatically publish scans from Elasticsearch CI
26-
if (jenkinsUrl?.host?.endsWith('elastic.co') || jenkinsUrl?.host?.endsWith('elastic.dev') || System.getenv('BUILDKITE') == 'true') {
29+
if (onCI) {
2730
publishing.onlyIf { true }
2831
server = 'https://gradle-enterprise.elastic.co'
2932
} else if( server.isPresent() == false) {
@@ -38,73 +41,9 @@ develocity {
3841
if (BuildParams.inFipsJvm) {
3942
tag 'FIPS'
4043
}
41-
42-
// Jenkins-specific build scan metadata
43-
if (jenkinsUrl) {
44-
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
45-
uploadInBackground = false
46-
47-
String buildNumber = System.getenv('BUILD_NUMBER')
48-
String buildUrl = System.getenv('BUILD_URL')
49-
String jobName = System.getenv('JOB_NAME')
50-
String nodeName = System.getenv('NODE_NAME')
51-
String jobBranch = System.getenv('ghprbTargetBranch') ?: System.getenv('JOB_BRANCH')
52-
53-
// Link to Jenkins worker logs and system metrics
54-
if (nodeName) {
55-
link 'System logs', "https://ci-stats.elastic.co/app/infra#/logs?&logFilter=(expression:'host.name:${nodeName}',kind:kuery)"
56-
buildFinished {
57-
link 'System metrics', "https://ci-stats.elastic.co/app/metrics/detail/host/${nodeName}"
58-
}
59-
}
60-
61-
// Parse job name in the case of matrix builds
62-
// Matrix job names come in the form of "base-job-name/matrix_param1=value1,matrix_param2=value2"
63-
def splitJobName = jobName.split('/')
64-
if (splitJobName.length > 1 && splitJobName.last() ==~ /^([a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-&\.]+,?)+$/) {
65-
def baseJobName = splitJobName.dropRight(1).join('/')
66-
tag baseJobName
67-
tag splitJobName.last()
68-
value 'Job Name', baseJobName
69-
def matrixParams = splitJobName.last().split(',')
70-
matrixParams.collect { it.split('=') }.each { param ->
71-
value "MATRIX_${param[0].toUpperCase()}", param[1]
72-
}
73-
} else {
74-
tag jobName
75-
value 'Job Name', jobName
76-
}
77-
78-
tag 'CI'
79-
link 'CI Build', buildUrl
80-
link 'GCP Upload',
81-
"https://console.cloud.google.com/storage/browser/_details/elasticsearch-ci-artifacts/jobs/${URLEncoder.encode(jobName, "UTF-8")}/build/${buildNumber}.tar.bz2"
82-
value 'Job Number', buildNumber
83-
if (jobBranch) {
84-
tag jobBranch
85-
value 'Git Branch', jobBranch
86-
}
87-
88-
System.getenv().getOrDefault('NODE_LABELS', '').split(' ').each {
89-
value 'Jenkins Worker Label', it
90-
}
91-
92-
// Add SCM information
93-
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
94-
if (isPrBuild) {
95-
value 'Git Commit ID', System.getenv('ghprbActualCommit')
96-
tag "pr/${System.getenv('ghprbPullId')}"
97-
tag 'pull-request'
98-
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
99-
link 'Pull Request', System.getenv('ghprbPullLink')
100-
} else {
101-
value 'Git Commit ID', BuildParams.gitRevision
102-
link 'Source', "https://github.com/elastic/elasticsearch/tree/${BuildParams.gitRevision}"
103-
}
104-
} else if (buildKiteUrl) { //Buildkite-specific build scan metadata
105-
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
106-
uploadInBackground = false
107-
44+
println "onCI = $onCI"
45+
if (onCI) { //Buildkite-specific build scan metadata
46+
String buildKiteUrl = System.getenv('BUILDKITE_BUILD_URL')
10847
def branch = System.getenv('BUILDKITE_PULL_REQUEST_BASE_BRANCH') ?: System.getenv('BUILDKITE_BRANCH')
10948
def repoMatcher = System.getenv('BUILDKITE_REPO') =~ /(https:\/\/github\.com\/|git@github\.com:)(\S+)\.git/
11049
def repository = repoMatcher.matches() ? repoMatcher.group(2) : "<unknown>"

0 commit comments

Comments
 (0)