Skip to content

Commit cf7ccb1

Browse files
authored
[Gradle] Fix build finished hooks on ci when using configuration cache (#116888) (#122740)
Fixes two incompatibilities with Gradle configuration cache in our build scan build finished hook: referencing static methods from build script referencing gradle object from closure (cherry picked from commit 929d398)
1 parent ae2d918 commit cf7ccb1

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ import java.time.LocalDateTime;
1212

1313
import org.elasticsearch.gradle.Architecture
1414
import org.elasticsearch.gradle.OS
15+
import static org.elasticsearch.gradle.internal.util.CiUtils.safeName
1516

1617
import java.lang.management.ManagementFactory
1718
import java.time.LocalDateTime
1819

20+
// Resolving this early to avoid issues with the build scan plugin in combination with the configuration cache usage
21+
def taskNames = gradle.startParameter.taskNames.join(' ')
22+
1923
develocity {
2024

2125
buildScan {
@@ -112,7 +116,7 @@ develocity {
112116

113117
// Add a build annotation
114118
// See: https://buildkite.com/docs/agent/v3/cli-annotate
115-
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>"""
119+
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>"""
116120
def process = [
117121
'buildkite-agent',
118122
'annotate',
@@ -133,7 +137,3 @@ develocity {
133137
}
134138
}
135139
}
136-
137-
static def safeName(String string) {
138-
return string.replaceAll(/[^a-zA-Z0-9_\-\.]+/, ' ').trim().replaceAll(' ', '_').toLowerCase()
139-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.util;
11+
12+
public class CiUtils {
13+
14+
static String safeName(String input) {
15+
return input.replaceAll("[^a-zA-Z0-9_\\-\\.]+", " ").trim().replaceAll(" ", "_").toLowerCase();
16+
}
17+
18+
}

0 commit comments

Comments
 (0)