Update develocity-injection init script to v2.0 (#593)

Updates the develocity-injection init script to the latest reference
script content
from https://github.com/gradle/develocity-ci-injection.

---------

Co-authored-by: daz <daz@gradle.com>
This commit is contained in:
Bot Githubaction 2025-04-04 21:39:30 +02:00 committed by GitHub
parent df11ab8fb2
commit 572d36861a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 99 additions and 87 deletions

View File

@ -27,9 +27,9 @@ jobs:
inject-develocity:
env:
DEVELOCITY_INJECTION_ENABLED: true
DEVELOCITY_URL: https://ge.solutions-team.gradle.com
DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_CCUD_PLUGIN_VERSION: '2.1'
DEVELOCITY_INJECTION_URL: https://ge.solutions-team.gradle.com
DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION: '2.1'
${{matrix.accessKeyEnv}}: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
strategy:
fail-fast: false
@ -74,9 +74,9 @@ jobs:
inject-develocity-with-access-key:
env:
DEVELOCITY_INJECTION_ENABLED: true
DEVELOCITY_URL: 'https://ge.solutions-team.gradle.com'
DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_CCUD_PLUGIN_VERSION: '2.1'
DEVELOCITY_INJECTION_URL: 'https://ge.solutions-team.gradle.com'
DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION: '2.1'
strategy:
fail-fast: false
matrix:
@ -115,9 +115,9 @@ jobs:
inject-develocity-short-lived-token-failed:
env:
DEVELOCITY_INJECTION_ENABLED: true
DEVELOCITY_URL: 'https://localhost:3333/'
DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_CCUD_PLUGIN_VERSION: '2.1'
DEVELOCITY_INJECTION_URL: 'https://localhost:3333/'
DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION: '2.1'
# Access key also set as an env var, we want to check it does not leak
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}

View File

@ -870,7 +870,7 @@ This access key will be used during the action execution to get a short-lived to
The `init-script` supports several additional configuration parameters that you may find useful. All configuration options (required and optional) are detailed below:
| Variable | Required | Description |
|--------------------------------------| --- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|--------------------------------------| :---: |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| develocity-injection-enabled | :white_check_mark: | enables Develocity injection |
| develocity-url | :white_check_mark: | the URL of the Develocity server |
| develocity-allow-untrusted-server | | allow communication with an untrusted server; set to _true_ if your Develocity instance is using a self-signed certificate |
@ -884,18 +884,18 @@ The `init-script` supports several additional configuration parameters that you
The input parameters can be expressed as environment variables following the relationships outlined in the table below:
| Input | Environment Variable |
|--------------------------------------|--------------------------------------|
| develocity-injection-enabled | DEVELOCITY_INJECTION_ENABLED |
| develocity-url | DEVELOCITY_URL |
| develocity-allow-untrusted-server | DEVELOCITY_ALLOW_UNTRUSTED_SERVER |
| develocity-capture-file-fingerprints | DEVELOCITY_CAPTURE_FILE_FINGERPRINTS |
| develocity-enforce-url | DEVELOCITY_ENFORCE_URL |
| develocity-plugin-version | DEVELOCITY_PLUGIN_VERSION |
| develocity-ccud-plugin-version | DEVELOCITY_CCUD_PLUGIN_VERSION |
| gradle-plugin-repository-url | GRADLE_PLUGIN_REPOSITORY_URL |
| gradle-plugin-repository-username | GRADLE_PLUGIN_REPOSITORY_USERNAME |
| gradle-plugin-repository-password | GRADLE_PLUGIN_REPOSITORY_PASSWORD |
| Input | Environment Variable |
|--------------------------------------|------------------------------------------------|
| develocity-injection-enabled | DEVELOCITY_INJECTION_ENABLED |
| develocity-url | DEVELOCITY_INJECTION_URL |
| develocity-enforce-url | DEVELOCITY_INJECTION_ENFORCE_URL |
| develocity-allow-untrusted-server | DEVELOCITY_INJECTION_ALLOW_UNTRUSTED_SERVER |
| develocity-capture-file-fingerprints | DEVELOCITY_INJECTION_CAPTURE_FILE_FINGERPRINTS |
| develocity-plugin-version | DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION |
| develocity-ccud-plugin-version | DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION |
| gradle-plugin-repository-url | DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_URL |
| gradle-plugin-repository-username | DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_USERNAME|
| gradle-plugin-repository-password | DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_PASSWORD|
Here's an example using the env vars:

View File

@ -4,28 +4,40 @@ import {setupToken} from './short-lived-token'
export async function setup(config: BuildScanConfig): Promise<void> {
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle')
maybeExportVariable('DEVELOCITY_AUTO_INJECTION_CUSTOM_VALUE', 'gradle-actions')
maybeExportVariable('DEVELOCITY_INJECTION_CUSTOM_VALUE', 'gradle-actions')
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_ENABLED', config.getDevelocityInjectionEnabled())
maybeExportVariableNotEmpty('DEVELOCITY_URL', config.getDevelocityUrl())
maybeExportVariableNotEmpty('DEVELOCITY_ALLOW_UNTRUSTED_SERVER', config.getDevelocityAllowUntrustedServer())
maybeExportVariableNotEmpty('DEVELOCITY_CAPTURE_FILE_FINGERPRINTS', config.getDevelocityCaptureFileFingerprints())
maybeExportVariableNotEmpty('DEVELOCITY_ENFORCE_URL', config.getDevelocityEnforceUrl())
maybeExportVariableNotEmpty('DEVELOCITY_PLUGIN_VERSION', config.getDevelocityPluginVersion())
maybeExportVariableNotEmpty('DEVELOCITY_CCUD_PLUGIN_VERSION', config.getDevelocityCcudPluginVersion())
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_URL', config.getGradlePluginRepositoryUrl())
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_USERNAME', config.getGradlePluginRepositoryUsername())
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_PASSWORD', config.getGradlePluginRepositoryPassword())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_URL', config.getDevelocityUrl())
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_ALLOW_UNTRUSTED_SERVER',
config.getDevelocityAllowUntrustedServer()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_CAPTURE_FILE_FINGERPRINTS',
config.getDevelocityCaptureFileFingerprints()
)
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_ENFORCE_URL', config.getDevelocityEnforceUrl())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION', config.getDevelocityPluginVersion())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION', config.getDevelocityCcudPluginVersion())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION__PLUGIN_REPOSITORY_URL', config.getGradlePluginRepositoryUrl())
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION__PLUGIN_REPOSITORY_USERNAME',
config.getGradlePluginRepositoryUsername()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION__PLUGIN_REPOSITORY_PASSWORD',
config.getGradlePluginRepositoryPassword()
)
// If build-scan-publish is enabled, ensure the environment variables are set
// The DEVELOCITY_PLUGIN_VERSION and DEVELOCITY_CCUD_PLUGIN_VERSION are set to the latest versions
// except if they are defined in the configuration
if (config.getBuildScanPublishEnabled()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true')
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.19.2')
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '2.1')
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
maybeExportVariable('DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION', '3.19.2')
maybeExportVariable('DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION', '2.1')
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
}
return setupToken(

View File

@ -1,6 +1,6 @@
/*
* Initscript for injection of Develocity into Gradle builds.
* Version: 1.3
* Version: 2.0
*/
import org.gradle.util.GradleVersion
@ -18,24 +18,24 @@ initscript {
return gradle.startParameter.systemPropertiesArgs[name] ?: System.getProperty(name) ?: System.getenv(envVarName)
}
def requestedInitScriptName = getInputParam(gradle, 'develocity.injection.init-script-name')
def requestedInitScriptName = getInputParam(gradle, 'develocity-injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
if (requestedInitScriptName != initScriptName) {
return
}
// Plugin loading is only required for Develocity injection. Abort early if not enabled.
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity.injection-enabled"))
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity-injection.enabled"))
if (!develocityInjectionEnabled) {
return
}
def pluginRepositoryUrl = getInputParam(gradle, 'gradle.plugin-repository.url')
def pluginRepositoryUsername = getInputParam(gradle, 'gradle.plugin-repository.username')
def pluginRepositoryPassword = getInputParam(gradle, 'gradle.plugin-repository.password')
def develocityPluginVersion = getInputParam(gradle, 'develocity.plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity.ccud-plugin.version')
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def pluginRepositoryUrl = getInputParam(gradle, 'develocity-injection.plugin-repository.url')
def pluginRepositoryUsername = getInputParam(gradle, 'develocity-injection.plugin-repository.username')
def pluginRepositoryPassword = getInputParam(gradle, 'develocity-injection.plugin-repository.password')
def develocityPluginVersion = getInputParam(gradle, 'develocity-injection.develocity-plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity-injection.ccud-plugin.version')
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
@ -91,10 +91,10 @@ if (!isTopLevelBuild) {
return
}
def requestedInitScriptName = getInputParam(gradle, 'develocity.injection.init-script-name')
def requestedInitScriptName = getInputParam(gradle, 'develocity-injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity.injection-enabled"))
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity-injection.enabled"))
if (develocityInjectionEnabled) {
if (requestedInitScriptName != initScriptName) {
logger.log(LogLevel.WARN, "Develocity injection not enabled because requested init script name was '${requestedInitScriptName}', but '${initScriptName}' was expected")
@ -127,17 +127,17 @@ void enableDevelocityInjection() {
def CCUD_PLUGIN_ID = 'com.gradle.common-custom-user-data-gradle-plugin'
def CCUD_PLUGIN_CLASS = 'com.gradle.CommonCustomUserDataGradlePlugin'
def develocityUrl = getInputParam(gradle, 'develocity.url')
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam(gradle, 'develocity.allow-untrusted-server'))
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam(gradle, 'develocity.enforce-url'))
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam(gradle, 'develocity.build-scan.upload-in-background'))
def develocityCaptureFileFingerprints = getInputParam(gradle, 'develocity.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam(gradle, 'develocity.capture-file-fingerprints')) : true
def develocityPluginVersion = getInputParam(gradle, 'develocity.plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity.ccud-plugin.version')
def buildScanTermsOfUseUrl = getInputParam(gradle, 'develocity.terms-of-use.url')
def buildScanTermsOfUseAgree = getInputParam(gradle, 'develocity.terms-of-use.agree')
def ciAutoInjectionCustomValueValue = getInputParam(gradle, 'develocity.auto-injection.custom-value')
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def develocityUrl = getInputParam(gradle, 'develocity-injection.url')
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.allow-untrusted-server'))
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.enforce-url'))
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.upload-in-background'))
def develocityCaptureFileFingerprints = getInputParam(gradle, 'develocity-injection.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.capture-file-fingerprints')) : true
def develocityPluginVersion = getInputParam(gradle, 'develocity-injection.develocity-plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity-injection.ccud-plugin.version')
def buildScanTermsOfUseUrl = getInputParam(gradle, 'develocity-injection.terms-of-use.url')
def buildScanTermsOfUseAgree = getInputParam(gradle, 'develocity-injection.terms-of-use.agree')
def ciAutoInjectionCustomValueValue = getInputParam(gradle, 'develocity-injection.custom-value')
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
@ -372,7 +372,7 @@ void enableDevelocityInjection() {
}
void applyPluginExternally(def pluginManager, String pluginClassName, String pluginVersion) {
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
logger.log(logLevel, "Applying $pluginClassName with version $pluginVersion via init script")
def externallyApplied = 'develocity.externally-applied'

View File

@ -490,43 +490,43 @@ class TestDevelocityInjection extends BaseInitScriptTest {
def getEnvVars() {
Map<String, String> envVars = [
DEVELOCITY_INJECTION_INIT_SCRIPT_NAME : "gradle-actions.inject-develocity.init.gradle",
DEVELOCITY_INJECTION_ENABLED : "true",
DEVELOCITY_URL : serverUrl,
DEVELOCITY_ALLOW_UNTRUSTED_SERVER : "true",
DEVELOCITY_PLUGIN_VERSION : develocityPluginVersion,
DEVELOCITY_BUILD_SCAN_UPLOAD_IN_BACKGROUND: "true", // Need to upload in background since our Mock server doesn't cope with foreground upload
DEVELOCITY_AUTO_INJECTION_CUSTOM_VALUE : 'gradle-actions',
DEVELOCITY_INJECTION_DEBUG : "true"
DEVELOCITY_INJECTION_INIT_SCRIPT_NAME : "gradle-actions.inject-develocity.init.gradle",
DEVELOCITY_INJECTION_ENABLED : "true",
DEVELOCITY_INJECTION_URL : serverUrl,
DEVELOCITY_INJECTION_ALLOW_UNTRUSTED_SERVER : "true",
DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION: develocityPluginVersion,
DEVELOCITY_INJECTION_UPLOAD_IN_BACKGROUND : "true", // Need to upload in background since our Mock server doesn't cope with foreground upload
DEVELOCITY_INJECTION_CUSTOM_VALUE : 'gradle-actions',
DEVELOCITY_INJECTION_DEBUG : "true"
]
if (enforceUrl) envVars.put("DEVELOCITY_ENFORCE_URL", "true")
if (ccudPluginVersion != null) envVars.put("DEVELOCITY_CCUD_PLUGIN_VERSION", ccudPluginVersion)
if (pluginRepositoryUrl != null) envVars.put("GRADLE_PLUGIN_REPOSITORY_URL", pluginRepositoryUrl)
if (pluginRepositoryUsername != null) envVars.put("GRADLE_PLUGIN_REPOSITORY_USERNAME", pluginRepositoryUsername)
if (pluginRepositoryPassword != null) envVars.put("GRADLE_PLUGIN_REPOSITORY_PASSWORD", pluginRepositoryPassword)
if (captureFileFingerprints) envVars.put("DEVELOCITY_CAPTURE_FILE_FINGERPRINTS", "true")
if (enforceUrl) envVars.put("DEVELOCITY_INJECTION_ENFORCE_URL", "true")
if (ccudPluginVersion != null) envVars.put("DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION", ccudPluginVersion)
if (captureFileFingerprints) envVars.put("DEVELOCITY_INJECTION_CAPTURE_FILE_FINGERPRINTS", "true")
if (pluginRepositoryUrl != null) envVars.put("DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_URL", pluginRepositoryUrl)
if (pluginRepositoryUsername != null) envVars.put("DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_USERNAME", pluginRepositoryUsername)
if (pluginRepositoryPassword != null) envVars.put("DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_PASSWORD", pluginRepositoryPassword)
return envVars
}
def getJvmArgs() {
List<String> jvmArgs = [
"-Ddevelocity.injection.init-script-name=gradle-actions.inject-develocity.init.gradle",
"-Ddevelocity.injection-enabled=true",
"-Ddevelocity.url=$serverUrl",
"-Ddevelocity.allow-untrusted-server=true",
"-Ddevelocity.plugin.version=$develocityPluginVersion",
"-Ddevelocity.build-scan.upload-in-background=true",
"-Ddevelocity.auto-injection.custom-value=gradle-actions",
"-Ddevelocity.injection.debug=true"
"-Ddevelocity-injection.init-script-name=gradle-actions.inject-develocity.init.gradle",
"-Ddevelocity-injection.enabled=true",
"-Ddevelocity-injection.url=$serverUrl",
"-Ddevelocity-injection.allow-untrusted-server=true",
"-Ddevelocity-injection.develocity-plugin.version=$develocityPluginVersion",
"-Ddevelocity-injection.upload-in-background=true",
"-Ddevelocity-injection.custom-value=gradle-actions",
"-Ddevelocity-injection.debug=true"
]
if (enforceUrl) jvmArgs.add("-Ddevelocity.enforce-url=true")
if (ccudPluginVersion != null) jvmArgs.add("-Ddevelocity.ccud-plugin.version=$ccudPluginVersion")
if (pluginRepositoryUrl != null) jvmArgs.add("-Dgradle.plugin-repository.url=$pluginRepositoryUrl")
if (pluginRepositoryUsername != null) jvmArgs.add("-Dgradle.plugin-repository.username=$pluginRepositoryUsername")
if (pluginRepositoryPassword != null) jvmArgs.add("-Dgradle.plugin-repository.password=$pluginRepositoryPassword")
if (captureFileFingerprints) jvmArgs.add("-Ddevelocity.capture-file-fingerprints=true")
if (enforceUrl) jvmArgs.add("-Ddevelocity-injection.enforce-url=true")
if (ccudPluginVersion != null) jvmArgs.add("-Ddevelocity-injection.ccud-plugin.version=$ccudPluginVersion")
if (captureFileFingerprints) jvmArgs.add("-Ddevelocity-injection.capture-file-fingerprints=true")
if (pluginRepositoryUrl != null) jvmArgs.add("-Ddevelocity-injection.plugin-repository.url=$pluginRepositoryUrl")
if (pluginRepositoryUsername != null) jvmArgs.add("-Ddevelocity-injection.plugin-repository.username=$pluginRepositoryUsername")
if (pluginRepositoryPassword != null) jvmArgs.add("-Ddevelocity-injection.plugin-repository.password=$pluginRepositoryPassword")
return jvmArgs.collect { it.toString() } // Convert from GStrings
}