Skip to content

Commit 2fbd8be

Browse files
authoredNov 6, 2024··
Merge pull request #675 from gradle/erichaagdev/use-envs
Use environment variables to configure Gradle init scripts
2 parents 5a22aff + 95707cf commit 2fbd8be

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed
 

‎components/scripts/gradle/05-validate-remote-build-caching-ci-local.sh

+9-10
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,18 @@ validate_build_config() {
194194
}
195195

196196
execute_build() {
197-
local args
198-
args=(--build-cache --init-script "${INIT_SCRIPTS_DIR}/configure-remote-build-caching.gradle")
199-
if [ -n "${remote_build_cache_url}" ]; then
200-
args+=("-Ddevelocity.build-validation.remoteBuildCacheUrl=${remote_build_cache_url}")
201-
fi
197+
info "Running build:"
198+
print_gradle_command
202199

203-
# shellcheck disable=SC2206 # we want tasks to expand with word splitting in this case
204-
args+=(clean ${tasks})
200+
# shellcheck disable=SC2086 # we want tasks to expand with word splitting in this case
201+
invoke_gradle 1 \
202+
--build-cache \
203+
--init-script "${INIT_SCRIPTS_DIR}/configure-remote-build-caching.gradle" \
204+
clean ${tasks}
205+
}
205206

206-
info "Running build:"
207+
print_gradle_command() {
207208
info "./gradlew --build-cache -Dscan.tag.${EXP_SCAN_TAG} -Dscan.value.runId=${RUN_ID} -Dpts.enabled=false clean ${tasks}$(print_extra_args)"
208-
209-
invoke_gradle 1 "${args[@]}"
210209
}
211210

212211
# Overrides summary.sh#print_experiment_specific_summary_info

‎components/scripts/lib/gradle.sh

+37-23
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22

33
invoke_gradle() {
4-
local run_num args
5-
args=()
4+
local run_num envs
5+
envs=()
66
run_num=$1
77
shift
88

@@ -12,35 +12,45 @@ invoke_gradle() {
1212
cd "${project_dir}" > /dev/null 2>&1 || die "ERROR: Subdirectory ${project_dir} (set with --project-dir) does not exist in ${project_name}" "${INVALID_INPUT}"
1313
fi
1414

15-
args+=(
16-
--init-script "${INIT_SCRIPTS_DIR}/develocity-injection.gradle"
17-
--init-script "${INIT_SCRIPTS_DIR}/configure-build-validation.gradle"
18-
-Ddevelocity.injection.init-script-name=develocity-injection.gradle
19-
-Ddevelocity.injection-enabled=true
15+
envs+=(
16+
DEVELOCITY_INJECTION_INIT_SCRIPT_NAME=develocity-injection.gradle
17+
DEVELOCITY_INJECTION_ENABLED=true
2018
)
2119

2220
if [ "$enable_ge" == "on" ]; then
23-
args+=(
24-
-Dgradle.plugin-repository.url=https://plugins.gradle.org/m2
25-
-Ddevelocity.plugin.version="3.14.1"
26-
-Ddevelocity.ccud.plugin.version="2.0.2"
21+
envs+=(
22+
GRADLE_PLUGIN_REPOSITORY_URL=https://plugins.gradle.org/m2
23+
DEVELOCITY_PLUGIN_VERSION="3.14.1"
24+
DEVELOCITY_CCUD_PLUGIN_VERSION="2.0.2"
2725
)
2826
fi
2927

3028
if [ -n "${ge_server}" ]; then
31-
args+=(
32-
-Ddevelocity.build-validation.url="${ge_server}"
33-
-Ddevelocity.build-validation.allow-untrusted-server=false
29+
envs+=(
30+
DEVELOCITY_BUILD_VALIDATION_URL="${ge_server}"
31+
DEVELOCITY_BUILD_VALIDATION_ALLOW_UNTRUSTED_SERVER=false
32+
)
33+
fi
34+
35+
if [ -n "${remote_build_cache_url}" ]; then
36+
envs+=(
37+
DEVELOCITY_BUILD_VALIDATION_REMOTEBUILDCACHEURL="${remote_build_cache_url}"
3438
)
3539
fi
3640

37-
args+=(
38-
-Ddevelocity.build-validation.expDir="${EXP_DIR}"
39-
-Ddevelocity.build-validation.expId="${EXP_SCAN_TAG}"
40-
-Ddevelocity.build-validation.runId="${RUN_ID}"
41-
-Ddevelocity.build-validation.runNum="${run_num}"
42-
-Ddevelocity.build-validation.scriptsVersion="${SCRIPT_VERSION}"
43-
-Ddevelocity.capture-file-fingerprints=true
41+
envs+=(
42+
DEVELOCITY_BUILD_VALIDATION_EXPDIR="${EXP_DIR}"
43+
DEVELOCITY_BUILD_VALIDATION_EXPID="${EXP_SCAN_TAG}"
44+
DEVELOCITY_BUILD_VALIDATION_RUNID="${RUN_ID}"
45+
DEVELOCITY_BUILD_VALIDATION_RUNNUM="${run_num}"
46+
DEVELOCITY_BUILD_VALIDATION_SCRIPTSVERSION="${SCRIPT_VERSION}"
47+
DEVELOCITY_CAPTURE_FILE_FINGERPRINTS=true
48+
)
49+
50+
local args
51+
args=(
52+
--init-script "${INIT_SCRIPTS_DIR}/develocity-injection.gradle"
53+
--init-script "${INIT_SCRIPTS_DIR}/configure-build-validation.gradle"
4454
-Dpts.enabled=false
4555
)
4656

@@ -57,9 +67,13 @@ invoke_gradle() {
5767
rm -f "${EXP_DIR}/errors.txt"
5868

5969
debug "Current directory: $(pwd)"
60-
debug ./gradlew "${args[@]}"
70+
# shellcheck disable=SC2145
71+
debug export "${envs[@]}"';' ./gradlew "${args[@]}"
6172

62-
if ./gradlew "${args[@]}"; then
73+
# The parenthesis below will intentionally create a subshell. This causes the
74+
# environment variables to only be exported for the child process and not leak
75+
# to the rest of the script.
76+
if (export "${envs[@]}"; ./gradlew "${args[@]}"); then
6377
build_outcomes+=("SUCCESSFUL")
6478
else
6579
build_outcomes+=("FAILED")

‎release/changes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
> [!IMPORTANT]
22
> The distributions of the Develocity Build Validation Scripts prefixed with `gradle-enterprise` are deprecated and will be removed in a future release. Migrate to the distributions prefixed with `develocity` instead.
33
4-
- [NEW] TBD
4+
- [FIX] Scripts fail for Gradle 7.0.2 and older under certain conditions

0 commit comments

Comments
 (0)
Please sign in to comment.