@@ -10,13 +10,10 @@ import org.elasticsearch.gradle.Architecture
10
10
import org.elasticsearch.gradle.OS
11
11
import org.elasticsearch.gradle.internal.info.BuildParams
12
12
import org.gradle.initialization.BuildRequestMetaData
13
- import org.elasticsearch.gradle.internal.test.rerun.TestRerunPlugin
14
- import java.util.concurrent.TimeUnit
15
-
16
- long startTime = project. gradle. services. get(BuildRequestMetaData ). getStartTime()
17
13
18
14
buildScan {
19
15
URL jenkinsUrl = System . getenv(' JENKINS_URL' ) ? new URL (System . getenv(' JENKINS_URL' )) : null
16
+ String buildKiteUrl = System . getenv(' BUILDKITE_BUILD_URL' ) ? System . getenv(' BUILDKITE_BUILD_URL' ) : null
20
17
21
18
// Automatically publish scans from Elasticsearch CI
22
19
if (jenkinsUrl?. host?. endsWith(' elastic.co' ) || jenkinsUrl?. host?. endsWith(' elastic.dev' )) {
@@ -25,12 +22,6 @@ buildScan {
25
22
}
26
23
27
24
background {
28
- String buildNumber = System . getenv(' BUILD_NUMBER' )
29
- String buildUrl = System . getenv(' BUILD_URL' )
30
- String jobName = System . getenv(' JOB_NAME' )
31
- String nodeName = System . getenv(' NODE_NAME' )
32
- String jobBranch = System . getenv(' ghprbTargetBranch' ) ?: System . getenv(' JOB_BRANCH' )
33
-
34
25
tag OS . current(). name()
35
26
tag Architecture . current(). name()
36
27
@@ -39,23 +30,25 @@ buildScan {
39
30
tag ' FIPS'
40
31
}
41
32
42
- // Link to Jenkins worker logs and system metrics
43
- if (nodeName) {
44
- link ' System logs' , " https://ci-stats.elastic.co/app/infra#/logs?" +
45
- " &logFilter=(expression:'host.name:${ nodeName} ',kind:kuery)"
46
- buildFinished {
47
- link ' System metrics' , " https://ci-stats.elastic.co/app/metrics/detail/host/" +
48
- " ${ nodeName} ?_g=()&metricTime=(autoReload:!f,refreshInterval:5000," +
49
- " time:(from:${ startTime - TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)} ,interval:%3E%3D1m," +
50
- " to:${ System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)} ))"
51
- }
52
- }
53
-
54
33
// Jenkins-specific build scan metadata
55
34
if (jenkinsUrl) {
56
35
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
57
36
uploadInBackground = false
58
37
38
+ String buildNumber = System . getenv(' BUILD_NUMBER' )
39
+ String buildUrl = System . getenv(' BUILD_URL' )
40
+ String jobName = System . getenv(' JOB_NAME' )
41
+ String nodeName = System . getenv(' NODE_NAME' )
42
+ String jobBranch = System . getenv(' ghprbTargetBranch' ) ?: System . getenv(' JOB_BRANCH' )
43
+
44
+ // Link to Jenkins worker logs and system metrics
45
+ if (nodeName) {
46
+ link ' System logs' , " https://ci-stats.elastic.co/app/infra#/logs?&logFilter=(expression:'host.name:${ nodeName} ',kind:kuery)"
47
+ buildFinished {
48
+ link ' System metrics' , " https://ci-stats.elastic.co/app/metrics/detail/host/${ nodeName} "
49
+ }
50
+ }
51
+
59
52
// Parse job name in the case of matrix builds
60
53
// Matrix job names come in the form of "base-job-name/matrix_param1=value1,matrix_param2=value2"
61
54
def splitJobName = jobName. split(' /' )
@@ -98,26 +91,45 @@ buildScan {
98
91
value ' Git Commit ID' , BuildParams . gitRevision
99
92
link ' Source' , " https://github.com/elastic/elasticsearch/tree/${ BuildParams.gitRevision} "
100
93
}
94
+ } else if (buildKiteUrl) { // Buildkite-specific build scan metadata
95
+ // Disable async upload in CI to ensure scan upload completes before CI agent is terminated
96
+ uploadInBackground = false
97
+
98
+ def branch = System . getenv(' BUILDKITE_BRANCH' )
99
+ def repoMatcher = System . getenv(' BUILDKITE_REPO' ) =~ / (https:\/\/ github\. com\/ |git@github\. com:)(\S +)\. git/
100
+ def repository = repoMatcher. matches() ? repoMatcher. group(2 ) : " <unknown>"
101
+ tag ' CI'
102
+ link ' CI Build' , buildKiteUrl
103
+ value ' Job Number' , System . getenv(' BUILDKITE_BUILD_NUMBER' )
104
+
105
+
106
+ // Add SCM information
107
+ def prId = System . getenv(' BUILDKITE_PULL_REQUEST' )
108
+ if (prId) {
109
+ def prBaseUrl = (System . getenv(' BUILDKITE_PULL_REQUEST_REPO' ) - " .git" )
110
+ value ' Git Commit ID' , System . getenv(' BUILDKITE_COMMIT' )
111
+ tag " pr/${ prId} "
112
+ tag ' pull-request'
113
+ link ' Source' , " ${ prBaseUrl} /tree/${ System.getenv('BUILDKITE_COMMIT')} "
114
+ link ' Pull Request' , " https://github.com/${ repository} /pull/${ prId} "
115
+ } else {
116
+ value ' Git Commit ID' , BuildParams . gitRevision
117
+ link ' Source' , " https://github.com/${ repository} /tree/${ BuildParams.gitRevision} "
118
+ tag branch
119
+ }
120
+
121
+ buildScanPublished { scan ->
122
+ // Attach build scan link as build metadata
123
+ // See: https://buildkite.com/docs/pipelines/build-meta-data
124
+ [' buildkite-agent' , ' meta-data' , ' set' , " build-scan-${ System.getenv('BUILDKITE_JOB_ID')} " , " ${ scan.buildScanUri} " ]. execute()
125
+
126
+ // Add a build annotation
127
+ // See: https://buildkite.com/docs/agent/v3/cli-annotate
128
+ def body = """ <div class="mb3"><span class="p1 border rounded">${ System.getenv('BUILDKITE_LABEL')} </span> :gradle: build ran: <a href="${ scan.buildScanUri} "><code>gradle ${ gradle.startParameter.taskNames.join(' ')} </code></a></div>"""
129
+ [' buildkite-agent' , ' annotate' , ' --context' , ' gradle-build-scans' , ' --append' , ' --style' , ' info' , body]. execute()
130
+ }
101
131
} else {
102
132
tag ' LOCAL'
103
133
}
104
134
}
105
135
}
106
-
107
- subprojects {
108
- project. getPlugins(). withType(TestRerunPlugin ) {
109
- tasks. withType(Test ). configureEach(new Action<Test > () {
110
- @Override
111
- void execute (Test test ) {
112
- test. doLast(new Action<Test > () {
113
- @Override
114
- void execute (Test t ) {
115
- if (t. rerun. didRerun. get() == true ) {
116
- buildScan. tag ' unexpected-test-jvm-exit'
117
- }
118
- }
119
- })
120
- }
121
- })
122
- }
123
- }
0 commit comments