@@ -12,168 +12,179 @@ import java.time.LocalDateTime;
12
12
import org.elasticsearch.gradle.Architecture
13
13
import org.elasticsearch.gradle.OS
14
14
import org.elasticsearch.gradle.internal.info.BuildParams
15
- import org.gradle.initialization.BuildRequestMetaData
16
15
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
20
18
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 {
26
20
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
30
24
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'
34
29
}
35
30
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'
53
39
}
54
40
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
+ }
66
58
}
67
- } else {
68
- tag jobName
69
- value ' Job Name' , jobName
70
- }
71
59
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
+ }
80
76
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
+ }
84
86
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
121
89
}
122
- }
123
90
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
127
106
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)
130
112
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' )
135
118
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' )
149
121
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
+ }
173
128
}
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'
174
187
}
175
- } else {
176
- tag ' LOCAL'
177
188
}
178
189
}
179
190
}
0 commit comments