|
1 | 1 | import org.elasticsearch.hadoop.gradle.buildtools.ConcatFilesTask
|
| 2 | +import java.lang.management.ManagementFactory; |
| 3 | +import java.time.LocalDateTime; |
2 | 4 |
|
| 5 | +import org.elasticsearch.gradle.Architecture |
| 6 | +import org.elasticsearch.gradle.OS |
| 7 | +import static org.elasticsearch.hadoop.gradle.util.CiUtils.safeName |
| 8 | + |
| 9 | +import java.lang.management.ManagementFactory |
| 10 | +import java.time.LocalDateTime |
3 | 11 | description = 'Elasticsearch for Apache Hadoop'
|
4 | 12 |
|
5 | 13 | apply plugin: 'es.hadoop.build.root'
|
@@ -43,3 +51,117 @@ if (project.hasProperty("find-artifact")) {
|
43 | 51 | }
|
44 | 52 | }
|
45 | 53 | }
|
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +// Resolving this early to avoid issues with the build scan plugin in combination with the configuration cache usage |
| 58 | +def taskNames = gradle.startParameter.taskNames.join(' ') |
| 59 | + |
| 60 | +develocity { |
| 61 | + |
| 62 | + buildScan { |
| 63 | + |
| 64 | + def onCI = System.getenv('CI') ? Boolean.parseBoolean(System.getenv('CI')) : false |
| 65 | + |
| 66 | + // Disable async upload in CI to ensure scan upload completes before CI agent is terminated |
| 67 | + uploadInBackground = onCI == false |
| 68 | + |
| 69 | + // Automatically publish scans from Elasticsearch CI |
| 70 | + if (onCI) { |
| 71 | + publishing.onlyIf { true } |
| 72 | + server = 'https://gradle-enterprise.elastic.co' |
| 73 | + } else if( server.isPresent() == false) { |
| 74 | + publishing.onlyIf { false } |
| 75 | + } |
| 76 | + |
| 77 | + background { |
| 78 | + tag OS.current().name() |
| 79 | + tag Architecture.current().name() |
| 80 | + |
| 81 | + if (onCI) { //Buildkite-specific build scan metadata |
| 82 | + String buildKiteUrl = System.getenv('BUILDKITE_BUILD_URL') |
| 83 | + def branch = System.getenv('BUILDKITE_PULL_REQUEST_BASE_BRANCH') ?: System.getenv('BUILDKITE_BRANCH') |
| 84 | + def repoMatcher = System.getenv('BUILDKITE_REPO') =~ /(https:\/\/github\.com\/|git@github\.com:)(\S+)\.git/ |
| 85 | + def repository = repoMatcher.matches() ? repoMatcher.group(2) : "<unknown>" |
| 86 | + def jobLabel = System.getenv('BUILDKITE_LABEL') ?: '' |
| 87 | + def jobName = safeName(jobLabel) |
| 88 | + |
| 89 | + tag 'CI' |
| 90 | + link 'CI Build', "${buildKiteUrl}#${System.getenv('BUILDKITE_JOB_ID')}" |
| 91 | + value 'Job Number', System.getenv('BUILDKITE_BUILD_NUMBER') |
| 92 | + value 'Build ID', System.getenv('BUILDKITE_BUILD_ID') |
| 93 | + value 'Job ID', System.getenv('BUILDKITE_JOB_ID') |
| 94 | + |
| 95 | + value 'Pipeline', System.getenv('BUILDKITE_PIPELINE_SLUG') |
| 96 | + tag System.getenv('BUILDKITE_PIPELINE_SLUG') |
| 97 | + |
| 98 | + value 'Job Name', jobName |
| 99 | + tag jobName |
| 100 | + if (jobLabel.contains("/")) { |
| 101 | + jobLabel.split("/").collect { safeName(it) }.each { matrix -> |
| 102 | + tag matrix |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + def uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000; |
| 107 | + def metricsStartTime = LocalDateTime.now().minusSeconds(uptime.longValue()).minusMinutes(15).toString() |
| 108 | + def metricsEndTime = LocalDateTime.now().plusMinutes(15).toString() |
| 109 | + |
| 110 | + link 'Agent Metrics', |
| 111 | + "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))" |
| 112 | + link 'Agent Logs', |
| 113 | + "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))" |
| 114 | + |
| 115 | + if (branch) { |
| 116 | + tag branch |
| 117 | + value 'Git Branch', branch |
| 118 | + } |
| 119 | + |
| 120 | + // Add SCM information |
| 121 | + def prId = System.getenv('BUILDKITE_PULL_REQUEST') |
| 122 | + if (prId != 'false') { |
| 123 | + def prBaseUrl = (System.getenv('BUILDKITE_PULL_REQUEST_REPO') - ".git").replaceFirst("git://", "https://") |
| 124 | + value 'Git Commit ID', System.getenv('BUILDKITE_COMMIT') |
| 125 | + tag "pr/${prId}" |
| 126 | + tag 'pull-request' |
| 127 | + link 'Source', "${prBaseUrl}/tree/${System.getenv('BUILDKITE_COMMIT')}" |
| 128 | + link 'Pull Request', "https://github.com/${repository}/pull/${prId}" |
| 129 | + } else { |
| 130 | + value 'Git Commit ID', System.getenv('BUILDKITE_COMMIT') |
| 131 | + link 'Source', "https://github.com/${repository}/tree/${System.getenv('BUILDKITE_COMMIT')}" |
| 132 | + } |
| 133 | + |
| 134 | + buildFinished { result -> |
| 135 | + |
| 136 | + buildScanPublished { scan |
| 137 | + -> |
| 138 | + // Attach build scan link as build metadata |
| 139 | + // See: https://buildkite.com/docs/pipelines/build-meta-data |
| 140 | + new ProcessBuilder('buildkite-agent', 'meta-data', 'set', "build-scan-${System.getenv('BUILDKITE_JOB_ID')}", "${scan.buildScanUri}") |
| 141 | + .start() |
| 142 | + .waitFor() |
| 143 | + |
| 144 | + // Add a build annotation |
| 145 | + // See: https://buildkite.com/docs/agent/v3/cli-annotate |
| 146 | + 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 ${taskNames}</code></a></div>""" |
| 147 | + def process = [ |
| 148 | + 'buildkite-agent', |
| 149 | + 'annotate', |
| 150 | + '--context', |
| 151 | + result.failures ? 'gradle-build-scans-failed' : 'gradle-build-scans', |
| 152 | + '--append', |
| 153 | + '--style', |
| 154 | + result.failures ? 'error' : 'info' |
| 155 | + ].execute() |
| 156 | + process.withWriter { it.write(body) } |
| 157 | + // passing the body in as an argument has issues on Windows, so let's use stdin of the process instead |
| 158 | + process.waitFor() |
| 159 | + } |
| 160 | + } |
| 161 | + } else { |
| 162 | + tag 'LOCAL' |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | +} |
| 167 | + |
0 commit comments