Skip to content

Commit 35a2ee3

Browse files
authored
Build: Add git hashes used as build metadata (#26397)
This commit adds files to the build output called build_metadata which contain key/value pairs of metadata associated with the build. The first use of this metadata are the git hashes associated with bwc checkouts. These metadata files will be picked up by CI intake jobs and stored along with last-good-commit, and then passed back in throug the BUILD_METADATA env var on periodic jobs.
1 parent 86d9797 commit 35a2ee3

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ if (currentVersion.bugfix == 0) {
127127
}
128128
}
129129

130+
// build metadata from previous build, contains eg hashes for bwc builds
131+
String buildMetadataValue = System.getenv('BUILD_METADATA')
132+
if (buildMetadataValue == null) {
133+
buildMetadataValue = ''
134+
}
135+
Map<String, String> buildMetadataMap = buildMetadataValue.tokenize(';').collectEntries {
136+
def (String key, String value) = it.split('=')
137+
return [key, value]
138+
}
139+
130140
// injecting groovy property variables into all projects
131141
allprojects {
132142
project.ext {
@@ -136,6 +146,7 @@ allprojects {
136146
// for backcompat testing
137147
indexCompatVersions = versions
138148
wireCompatVersions = versions.subList(prevMinorIndex, versions.size())
149+
buildMetadata = buildMetadataMap
139150
}
140151
}
141152

distribution/bwc/build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,37 @@ if (enabled) {
105105
}
106106

107107
// this is an Exec task so that the SHA that is checked out is logged
108+
String buildMetadataKey = "bwc_refspec_${project.path.substring(1)}"
108109
task checkoutBwcBranch(type: Exec) {
109-
def String refspec = System.getProperty("tests.bwc.refspec", "upstream/${bwcBranch}")
110+
def String refspec = System.getProperty("tests.bwc.refspec", buildMetadata.get(buildMetadataKey, "upstream/${bwcBranch}"))
110111
dependsOn fetchLatest
111112
workingDir = checkoutDir
112113
commandLine = ['git', 'checkout', refspec]
113114
}
114115

116+
File buildMetadataFile = project.file("build/${project.name}/build_metadata")
117+
task writeBuildMetadata(type: LoggedExec) {
118+
dependsOn checkoutBwcBranch
119+
workingDir = checkoutDir
120+
commandLine = ['git', 'rev-parse', 'HEAD']
121+
ignoreExitValue = true
122+
ByteArrayOutputStream output = new ByteArrayOutputStream()
123+
standardOutput = output
124+
doLast {
125+
if (execResult.exitValue != 0) {
126+
output.toString('UTF-8').eachLine { line -> logger.error(line) }
127+
execResult.assertNormalExitValue()
128+
}
129+
project.mkdir(buildMetadataFile.parent)
130+
buildMetadataFile.setText("${buildMetadataKey}=${output.toString('UTF-8')}", 'UTF-8')
131+
}
132+
}
133+
115134
File bwcDeb = file("${checkoutDir}/distribution/deb/build/distributions/elasticsearch-${bwcVersion}.deb")
116135
File bwcRpm = file("${checkoutDir}/distribution/rpm/build/distributions/elasticsearch-${bwcVersion}.rpm")
117136
File bwcZip = file("${checkoutDir}/distribution/zip/build/distributions/elasticsearch-${bwcVersion}.zip")
118137
task buildBwcVersion(type: GradleBuild) {
119-
dependsOn checkoutBwcBranch
138+
dependsOn checkoutBwcBranch, writeBuildMetadata
120139
dir = checkoutDir
121140
tasks = [':distribution:deb:assemble', ':distribution:rpm:assemble', ':distribution:zip:assemble']
122141
doLast {

0 commit comments

Comments
 (0)