Skip to content

Use environment variables to configure Gradle init scripts #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,18 @@ validate_build_config() {
}

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

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

info "Running build:"
print_gradle_command() {
info "./gradlew --build-cache -Dscan.tag.${EXP_SCAN_TAG} -Dscan.value.runId=${RUN_ID} -Dpts.enabled=false clean ${tasks}$(print_extra_args)"

invoke_gradle 1 "${args[@]}"
}

# Overrides summary.sh#print_experiment_specific_summary_info
Expand Down
60 changes: 37 additions & 23 deletions components/scripts/lib/gradle.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

invoke_gradle() {
local run_num args
args=()
local run_num envs
envs=()
run_num=$1
shift

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

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

if [ "$enable_ge" == "on" ]; then
args+=(
-Dgradle.plugin-repository.url=https://plugins.gradle.org/m2
-Ddevelocity.plugin.version="3.14.1"
-Ddevelocity.ccud.plugin.version="2.0.2"
envs+=(
GRADLE_PLUGIN_REPOSITORY_URL=https://plugins.gradle.org/m2
DEVELOCITY_PLUGIN_VERSION="3.14.1"
DEVELOCITY_CCUD_PLUGIN_VERSION="2.0.2"
)
fi

if [ -n "${ge_server}" ]; then
args+=(
-Ddevelocity.build-validation.url="${ge_server}"
-Ddevelocity.build-validation.allow-untrusted-server=false
envs+=(
DEVELOCITY_BUILD_VALIDATION_URL="${ge_server}"
DEVELOCITY_BUILD_VALIDATION_ALLOW_UNTRUSTED_SERVER=false
)
fi

if [ -n "${remote_build_cache_url}" ]; then
envs+=(
DEVELOCITY_BUILD_VALIDATION_REMOTEBUILDCACHEURL="${remote_build_cache_url}"
)
fi

args+=(
-Ddevelocity.build-validation.expDir="${EXP_DIR}"
-Ddevelocity.build-validation.expId="${EXP_SCAN_TAG}"
-Ddevelocity.build-validation.runId="${RUN_ID}"
-Ddevelocity.build-validation.runNum="${run_num}"
-Ddevelocity.build-validation.scriptsVersion="${SCRIPT_VERSION}"
-Ddevelocity.capture-file-fingerprints=true
envs+=(
DEVELOCITY_BUILD_VALIDATION_EXPDIR="${EXP_DIR}"
DEVELOCITY_BUILD_VALIDATION_EXPID="${EXP_SCAN_TAG}"
DEVELOCITY_BUILD_VALIDATION_RUNID="${RUN_ID}"
DEVELOCITY_BUILD_VALIDATION_RUNNUM="${run_num}"
DEVELOCITY_BUILD_VALIDATION_SCRIPTSVERSION="${SCRIPT_VERSION}"
DEVELOCITY_CAPTURE_FILE_FINGERPRINTS=true
)

local args
args=(
--init-script "${INIT_SCRIPTS_DIR}/develocity-injection.gradle"
--init-script "${INIT_SCRIPTS_DIR}/configure-build-validation.gradle"
-Dpts.enabled=false
)

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

debug "Current directory: $(pwd)"
debug ./gradlew "${args[@]}"
# shellcheck disable=SC2145
debug export "${envs[@]}"';' ./gradlew "${args[@]}"

if ./gradlew "${args[@]}"; then
# The parenthesis below will intentionally create a subshell. This causes the
# environment variables to only be exported for the child process and not leak
# to the rest of the script.
if (export "${envs[@]}"; ./gradlew "${args[@]}"); then
build_outcomes+=("SUCCESSFUL")
else
build_outcomes+=("FAILED")
Expand Down
2 changes: 1 addition & 1 deletion release/changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> [!IMPORTANT]
> 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.

- [NEW] TBD
- [FIX] Scripts fail for Gradle 7.0.2 and older under certain conditions