Skip to content

Commit

Permalink
[Gradle] Fix build finished hooks on ci when using configuration cache (
Browse files Browse the repository at this point in the history
elastic#116888)

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
  • Loading branch information
breskeby authored Nov 18, 2024
1 parent 058be96 commit 929d398
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import java.time.LocalDateTime;

import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.OS
import static org.elasticsearch.gradle.internal.util.CiUtils.safeName

import java.lang.management.ManagementFactory
import java.time.LocalDateTime

// Resolving this early to avoid issues with the build scan plugin in combination with the configuration cache usage
def taskNames = gradle.startParameter.taskNames.join(' ')

develocity {

buildScan {
Expand Down Expand Up @@ -110,7 +114,7 @@ develocity {

// Add a build annotation
// See: https://buildkite.com/docs/agent/v3/cli-annotate
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>"""
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>"""
def process = [
'buildkite-agent',
'annotate',
Expand All @@ -131,7 +135,3 @@ develocity {
}
}
}

static def safeName(String string) {
return string.replaceAll(/[^a-zA-Z0-9_\-\.]+/, ' ').trim().replaceAll(' ', '_').toLowerCase()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.gradle.internal.util;

public class CiUtils {

static String safeName(String input) {
return input.replaceAll("[^a-zA-Z0-9_\\-\\.]+", " ").trim().replaceAll(" ", "_").toLowerCase();
}

}

0 comments on commit 929d398

Please sign in to comment.