Skip to content

Commit 02439e3

Browse files
authored
Update Gradle gradleEnterprise plugin (develocity now) (elastic#109443)
* Update Gradle gradleEnterprise plugin (develocity now) * Fix imports in build scan script * Fix build scan api usage * Dependency cleanup and API fix * Fix API update for BuildResult in Build scans * Fix buildkite buildscan annotations based on gradle failures
1 parent 28faacd commit 02439e3

File tree

6 files changed

+161
-150
lines changed

6 files changed

+161
-150
lines changed

.ci/init.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ if (USE_ARTIFACTORY) {
9191
}
9292

9393
gradle.settingsEvaluated { settings ->
94-
settings.pluginManager.withPlugin("com.gradle.enterprise") {
95-
settings.gradleEnterprise {
94+
settings.pluginManager.withPlugin("com.gradle.develocity") {
95+
settings.develocity {
9696
server = 'https://gradle-enterprise.elastic.co'
9797
}
9898
}

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

+153-142
Original file line numberDiff line numberDiff line change
@@ -12,168 +12,179 @@ import java.time.LocalDateTime;
1212
import org.elasticsearch.gradle.Architecture
1313
import org.elasticsearch.gradle.OS
1414
import org.elasticsearch.gradle.internal.info.BuildParams
15-
import org.gradle.initialization.BuildRequestMetaData
1615

17-
buildScan {
18-
URL jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null
19-
String buildKiteUrl = System.getenv('BUILDKITE_BUILD_URL') ? System.getenv('BUILDKITE_BUILD_URL') : null
16+
import java.lang.management.ManagementFactory
17+
import java.time.LocalDateTime
2018

21-
// Automatically publish scans from Elasticsearch CI
22-
if (jenkinsUrl?.host?.endsWith('elastic.co') || jenkinsUrl?.host?.endsWith('elastic.dev') || System.getenv('BUILDKITE') == 'true') {
23-
publishAlways()
24-
buildScan.server = 'https://gradle-enterprise.elastic.co'
25-
}
19+
develocity {
2620

27-
background {
28-
tag OS.current().name()
29-
tag Architecture.current().name()
21+
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
3024

31-
// Tag if this build is run in FIPS mode
32-
if (BuildParams.inFipsJvm) {
33-
tag 'FIPS'
25+
// Automatically publish scans from Elasticsearch CI
26+
if (jenkinsUrl?.host?.endsWith('elastic.co') || jenkinsUrl?.host?.endsWith('elastic.dev') || System.getenv('BUILDKITE') == 'true') {
27+
publishing.onlyIf { true }
28+
server = 'https://gradle-enterprise.elastic.co'
3429
}
3530

36-
// Jenkins-specific build scan metadata
37-
if (jenkinsUrl) {
38-
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
39-
uploadInBackground = false
40-
41-
String buildNumber = System.getenv('BUILD_NUMBER')
42-
String buildUrl = System.getenv('BUILD_URL')
43-
String jobName = System.getenv('JOB_NAME')
44-
String nodeName = System.getenv('NODE_NAME')
45-
String jobBranch = System.getenv('ghprbTargetBranch') ?: System.getenv('JOB_BRANCH')
46-
47-
// Link to Jenkins worker logs and system metrics
48-
if (nodeName) {
49-
link 'System logs', "https://ci-stats.elastic.co/app/infra#/logs?&logFilter=(expression:'host.name:${nodeName}',kind:kuery)"
50-
buildFinished {
51-
link 'System metrics', "https://ci-stats.elastic.co/app/metrics/detail/host/${nodeName}"
52-
}
31+
32+
background {
33+
tag OS.current().name()
34+
tag Architecture.current().name()
35+
36+
// Tag if this build is run in FIPS mode
37+
if (BuildParams.inFipsJvm) {
38+
tag 'FIPS'
5339
}
5440

55-
// Parse job name in the case of matrix builds
56-
// Matrix job names come in the form of "base-job-name/matrix_param1=value1,matrix_param2=value2"
57-
def splitJobName = jobName.split('/')
58-
if (splitJobName.length > 1 && splitJobName.last() ==~ /^([a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-&\.]+,?)+$/) {
59-
def baseJobName = splitJobName.dropRight(1).join('/')
60-
tag baseJobName
61-
tag splitJobName.last()
62-
value 'Job Name', baseJobName
63-
def matrixParams = splitJobName.last().split(',')
64-
matrixParams.collect { it.split('=') }.each { param ->
65-
value "MATRIX_${param[0].toUpperCase()}", param[1]
41+
// Jenkins-specific build scan metadata
42+
if (jenkinsUrl) {
43+
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
44+
uploadInBackground = false
45+
46+
String buildNumber = System.getenv('BUILD_NUMBER')
47+
String buildUrl = System.getenv('BUILD_URL')
48+
String jobName = System.getenv('JOB_NAME')
49+
String nodeName = System.getenv('NODE_NAME')
50+
String jobBranch = System.getenv('ghprbTargetBranch') ?: System.getenv('JOB_BRANCH')
51+
52+
// Link to Jenkins worker logs and system metrics
53+
if (nodeName) {
54+
link 'System logs', "https://ci-stats.elastic.co/app/infra#/logs?&logFilter=(expression:'host.name:${nodeName}',kind:kuery)"
55+
buildFinished {
56+
link 'System metrics', "https://ci-stats.elastic.co/app/metrics/detail/host/${nodeName}"
57+
}
6658
}
67-
} else {
68-
tag jobName
69-
value 'Job Name', jobName
70-
}
7159

72-
tag 'CI'
73-
link 'CI Build', buildUrl
74-
link 'GCP Upload', "https://console.cloud.google.com/storage/browser/_details/elasticsearch-ci-artifacts/jobs/${URLEncoder.encode(jobName, "UTF-8")}/build/${buildNumber}.tar.bz2"
75-
value 'Job Number', buildNumber
76-
if (jobBranch) {
77-
tag jobBranch
78-
value 'Git Branch', jobBranch
79-
}
60+
// Parse job name in the case of matrix builds
61+
// Matrix job names come in the form of "base-job-name/matrix_param1=value1,matrix_param2=value2"
62+
def splitJobName = jobName.split('/')
63+
if (splitJobName.length > 1 && splitJobName.last() ==~ /^([a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-&\.]+,?)+$/) {
64+
def baseJobName = splitJobName.dropRight(1).join('/')
65+
tag baseJobName
66+
tag splitJobName.last()
67+
value 'Job Name', baseJobName
68+
def matrixParams = splitJobName.last().split(',')
69+
matrixParams.collect { it.split('=') }.each { param ->
70+
value "MATRIX_${param[0].toUpperCase()}", param[1]
71+
}
72+
} else {
73+
tag jobName
74+
value 'Job Name', jobName
75+
}
8076

81-
System.getenv().getOrDefault('NODE_LABELS', '').split(' ').each {
82-
value 'Jenkins Worker Label', it
83-
}
77+
tag 'CI'
78+
link 'CI Build', buildUrl
79+
link 'GCP Upload',
80+
"https://console.cloud.google.com/storage/browser/_details/elasticsearch-ci-artifacts/jobs/${URLEncoder.encode(jobName, "UTF-8")}/build/${buildNumber}.tar.bz2"
81+
value 'Job Number', buildNumber
82+
if (jobBranch) {
83+
tag jobBranch
84+
value 'Git Branch', jobBranch
85+
}
8486

85-
// Add SCM information
86-
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
87-
if (isPrBuild) {
88-
value 'Git Commit ID', System.getenv('ghprbActualCommit')
89-
tag "pr/${System.getenv('ghprbPullId')}"
90-
tag 'pull-request'
91-
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
92-
link 'Pull Request', System.getenv('ghprbPullLink')
93-
} else {
94-
value 'Git Commit ID', BuildParams.gitRevision
95-
link 'Source', "https://github.com/elastic/elasticsearch/tree/${BuildParams.gitRevision}"
96-
}
97-
} else if (buildKiteUrl) { //Buildkite-specific build scan metadata
98-
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
99-
uploadInBackground = false
100-
101-
def branch = System.getenv('BUILDKITE_PULL_REQUEST_BASE_BRANCH') ?: System.getenv('BUILDKITE_BRANCH')
102-
def repoMatcher = System.getenv('BUILDKITE_REPO') =~ /(https:\/\/github\.com\/|git@github\.com:)(\S+)\.git/
103-
def repository = repoMatcher.matches() ? repoMatcher.group(2) : "<unknown>"
104-
def jobLabel = System.getenv('BUILDKITE_LABEL') ?: ''
105-
def jobName = safeName(jobLabel)
106-
107-
tag 'CI'
108-
link 'CI Build', "${buildKiteUrl}#${System.getenv('BUILDKITE_JOB_ID')}"
109-
value 'Job Number', System.getenv('BUILDKITE_BUILD_NUMBER')
110-
value 'Build ID', System.getenv('BUILDKITE_BUILD_ID')
111-
value 'Job ID', System.getenv('BUILDKITE_JOB_ID')
112-
113-
value 'Pipeline', System.getenv('BUILDKITE_PIPELINE_SLUG')
114-
tag System.getenv('BUILDKITE_PIPELINE_SLUG')
115-
116-
value 'Job Name', jobName
117-
tag jobName
118-
if (jobLabel.contains("/")) {
119-
jobLabel.split("/").collect {safeName(it) }.each {matrix ->
120-
tag matrix
87+
System.getenv().getOrDefault('NODE_LABELS', '').split(' ').each {
88+
value 'Jenkins Worker Label', it
12189
}
122-
}
12390

124-
def uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000;
125-
def metricsStartTime = LocalDateTime.now().minusSeconds(uptime.longValue()).minusMinutes(15).toString()
126-
def metricsEndTime = LocalDateTime.now().plusMinutes(15).toString()
91+
// Add SCM information
92+
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
93+
if (isPrBuild) {
94+
value 'Git Commit ID', System.getenv('ghprbActualCommit')
95+
tag "pr/${System.getenv('ghprbPullId')}"
96+
tag 'pull-request'
97+
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
98+
link 'Pull Request', System.getenv('ghprbPullLink')
99+
} else {
100+
value 'Git Commit ID', BuildParams.gitRevision
101+
link 'Source', "https://github.com/elastic/elasticsearch/tree/${BuildParams.gitRevision}"
102+
}
103+
} else if (buildKiteUrl) { //Buildkite-specific build scan metadata
104+
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
105+
uploadInBackground = false
127106

128-
link 'Agent Metrics', "https://es-buildkite-agents.elastic.dev/app/metrics/detail/host/${System.getenv('BUILDKITE_AGENT_NAME')}?_a=(time:(from:%27${metricsStartTime}Z%27,interval:%3E%3D1m,to:%27${metricsEndTime}Z%27))"
129-
link 'Agent Logs', "https://es-buildkite-agents.elastic.dev/app/logs/stream?logFilter=(filters:!(),query:(language:kuery,query:%27host.name:%20${System.getenv('BUILDKITE_AGENT_NAME')}%27),timeRange:(from:%27${metricsStartTime}Z%27,to:%27${metricsEndTime}Z%27))"
107+
def branch = System.getenv('BUILDKITE_PULL_REQUEST_BASE_BRANCH') ?: System.getenv('BUILDKITE_BRANCH')
108+
def repoMatcher = System.getenv('BUILDKITE_REPO') =~ /(https:\/\/github\.com\/|git@github\.com:)(\S+)\.git/
109+
def repository = repoMatcher.matches() ? repoMatcher.group(2) : "<unknown>"
110+
def jobLabel = System.getenv('BUILDKITE_LABEL') ?: ''
111+
def jobName = safeName(jobLabel)
130112

131-
if (branch) {
132-
tag branch
133-
value 'Git Branch', branch
134-
}
113+
tag 'CI'
114+
link 'CI Build', "${buildKiteUrl}#${System.getenv('BUILDKITE_JOB_ID')}"
115+
value 'Job Number', System.getenv('BUILDKITE_BUILD_NUMBER')
116+
value 'Build ID', System.getenv('BUILDKITE_BUILD_ID')
117+
value 'Job ID', System.getenv('BUILDKITE_JOB_ID')
135118

136-
// Add SCM information
137-
def prId = System.getenv('BUILDKITE_PULL_REQUEST')
138-
if (prId != 'false') {
139-
def prBaseUrl = (System.getenv('BUILDKITE_PULL_REQUEST_REPO') - ".git").replaceFirst("git://", "https://")
140-
value 'Git Commit ID', System.getenv('BUILDKITE_COMMIT')
141-
tag "pr/${prId}"
142-
tag 'pull-request'
143-
link 'Source', "${prBaseUrl}/tree/${System.getenv('BUILDKITE_COMMIT')}"
144-
link 'Pull Request', "https://github.com/${repository}/pull/${prId}"
145-
} else {
146-
value 'Git Commit ID', BuildParams.gitRevision
147-
link 'Source', "https://github.com/${repository}/tree/${BuildParams.gitRevision}"
148-
}
119+
value 'Pipeline', System.getenv('BUILDKITE_PIPELINE_SLUG')
120+
tag System.getenv('BUILDKITE_PIPELINE_SLUG')
149121

150-
buildFinished { result ->
151-
152-
buildScanPublished { scan ->
153-
// Attach build scan link as build metadata
154-
// See: https://buildkite.com/docs/pipelines/build-meta-data
155-
new ProcessBuilder('buildkite-agent', 'meta-data', 'set', "build-scan-${System.getenv('BUILDKITE_JOB_ID')}", "${scan.buildScanUri}")
156-
.start()
157-
.waitFor()
158-
159-
// Add a build annotation
160-
// See: https://buildkite.com/docs/agent/v3/cli-annotate
161-
def body = """<div class="mb3"><span class="p1 border rounded">${System.getenv('BUILDKITE_LABEL')}</span> :gradle: ${result.failure ? 'failed' : 'successful'} build: <a href="${scan.buildScanUri}"><code>gradle ${gradle.startParameter.taskNames.join(' ')}</code></a></div>"""
162-
def process = [
163-
'buildkite-agent',
164-
'annotate',
165-
'--context',
166-
result.failure ? 'gradle-build-scans-failed' : 'gradle-build-scans',
167-
'--append',
168-
'--style',
169-
result.failure ? 'error' : 'info'
170-
].execute()
171-
process.withWriter { it.write(body) } // passing the body in as an argument has issues on Windows, so let's use stdin of the process instead
172-
process.waitFor()
122+
value 'Job Name', jobName
123+
tag jobName
124+
if (jobLabel.contains("/")) {
125+
jobLabel.split("/").collect { safeName(it) }.each { matrix ->
126+
tag matrix
127+
}
173128
}
129+
130+
def uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000;
131+
def metricsStartTime = LocalDateTime.now().minusSeconds(uptime.longValue()).minusMinutes(15).toString()
132+
def metricsEndTime = LocalDateTime.now().plusMinutes(15).toString()
133+
134+
link 'Agent Metrics',
135+
"https://es-buildkite-agents.elastic.dev/app/metrics/detail/host/${System.getenv('BUILDKITE_AGENT_NAME')}?_a=(time:(from:%27${metricsStartTime}Z%27,interval:%3E%3D1m,to:%27${metricsEndTime}Z%27))"
136+
link 'Agent Logs',
137+
"https://es-buildkite-agents.elastic.dev/app/logs/stream?logFilter=(filters:!(),query:(language:kuery,query:%27host.name:%20${System.getenv('BUILDKITE_AGENT_NAME')}%27),timeRange:(from:%27${metricsStartTime}Z%27,to:%27${metricsEndTime}Z%27))"
138+
139+
if (branch) {
140+
tag branch
141+
value 'Git Branch', branch
142+
}
143+
144+
// Add SCM information
145+
def prId = System.getenv('BUILDKITE_PULL_REQUEST')
146+
if (prId != 'false') {
147+
def prBaseUrl = (System.getenv('BUILDKITE_PULL_REQUEST_REPO') - ".git").replaceFirst("git://", "https://")
148+
value 'Git Commit ID', System.getenv('BUILDKITE_COMMIT')
149+
tag "pr/${prId}"
150+
tag 'pull-request'
151+
link 'Source', "${prBaseUrl}/tree/${System.getenv('BUILDKITE_COMMIT')}"
152+
link 'Pull Request', "https://github.com/${repository}/pull/${prId}"
153+
} else {
154+
value 'Git Commit ID', BuildParams.gitRevision
155+
link 'Source', "https://github.com/${repository}/tree/${BuildParams.gitRevision}"
156+
}
157+
158+
buildFinished { result ->
159+
160+
buildScanPublished { scan
161+
->
162+
// Attach build scan link as build metadata
163+
// See: https://buildkite.com/docs/pipelines/build-meta-data
164+
new ProcessBuilder('buildkite-agent', 'meta-data', 'set', "build-scan-${System.getenv('BUILDKITE_JOB_ID')}", "${scan.buildScanUri}")
165+
.start()
166+
.waitFor()
167+
168+
// Add a build annotation
169+
// See: https://buildkite.com/docs/agent/v3/cli-annotate
170+
def body = """<div class="mb3"><span class="p1 border rounded">${System.getenv('BUILDKITE_LABEL')}</span> :gradle: ${result.failures ? 'failed' : 'successful'} build: <a href="${scan.buildScanUri}"><code>gradle ${gradle.startParameter.taskNames.join(' ')}</code></a></div>"""
171+
def process = [
172+
'buildkite-agent',
173+
'annotate',
174+
'--context',
175+
result.failures ? 'gradle-build-scans-failed' : 'gradle-build-scans',
176+
'--append',
177+
'--style',
178+
result.failures ? 'error' : 'info'
179+
].execute()
180+
process.withWriter { it.write(body) }
181+
// passing the body in as an argument has issues on Windows, so let's use stdin of the process instead
182+
process.waitFor()
183+
}
184+
}
185+
} else {
186+
tag 'LOCAL'
174187
}
175-
} else {
176-
tag 'LOCAL'
177188
}
178189
}
179190
}

gradle/build.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ commons-codec = "commons-codec:commons-codec:1.11"
1717
commmons-io = "commons-io:commons-io:2.2"
1818
docker-compose = "com.avast.gradle:gradle-docker-compose-plugin:0.17.5"
1919
forbiddenApis = "de.thetaphi:forbiddenapis:3.6"
20-
gradle-enterprise = "com.gradle:gradle-enterprise-gradle-plugin:3.16.2"
20+
gradle-enterprise = "com.gradle:develocity-gradle-plugin:3.17.4"
2121
hamcrest = "org.hamcrest:hamcrest:2.1"
2222
httpcore = "org.apache.httpcomponents:httpcore:4.4.12"
2323
httpclient = "org.apache.httpcomponents:httpclient:4.5.14"

gradle/verification-metadata.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,9 @@
741741
<sha256 value="48234cd74e35d91a31a683820a35b5b6d11b55527f32a5b162c6757408b95d7a" origin="Generated by Gradle"/>
742742
</artifact>
743743
</component>
744-
<component group="com.gradle" name="gradle-enterprise-gradle-plugin" version="3.16.2">
745-
<artifact name="gradle-enterprise-gradle-plugin-3.16.2.jar">
746-
<sha256 value="e06ca9b1bf0fef710dc74ec969e5c0b4553b92a46224326165ceac0e5c37e0d3" origin="Generated by Gradle"/>
744+
<component group="com.gradle" name="develocity-gradle-plugin" version="3.17.4">
745+
<artifact name="develocity-gradle-plugin-3.17.4.jar">
746+
<sha256 value="e2b3f8a191b0b401b75c2c4542d3d1719814a4212e6920fae4f2f940678bfd99" origin="Generated by Gradle"/>
747747
</artifact>
748748
</component>
749749
<component group="com.h2database" name="h2" version="1.4.197">

plugins/examples/settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
plugins {
10-
id "com.gradle.enterprise" version "3.16.2"
10+
id "com.gradle.develocity" version "3.17.4"
1111
}
1212

1313
// Include all subdirectories as example projects

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pluginManagement {
1717
}
1818

1919
plugins {
20-
id "com.gradle.enterprise" version "3.16.2"
20+
id "com.gradle.develocity" version "3.17.4"
2121
id 'elasticsearch.java-toolchain'
2222
}
2323

0 commit comments

Comments
 (0)