diff --git a/qt6-after/qt6-migrated-legatus/new_docker_build.sh b/qt6-after/qt6-migrated-legatus/new_docker_build.sh index 2a342e0d5..2fd215213 100755 --- a/qt6-after/qt6-migrated-legatus/new_docker_build.sh +++ b/qt6-after/qt6-migrated-legatus/new_docker_build.sh @@ -8,8 +8,8 @@ set -euo pipefail # Lts/Proxies/TrainingAreaBase) inside the prebuilt Docker image and # optionally runs the Jenkins builder to produce the release DEB packages. # -# - Loads environment from .envrc -# - Validates MIGRATE_PIPELINE_ROOT and rti_license.dat +# - Resolves MIGRATE_PIPELINE_ROOT (exported variable, .envrc, or derived +# from the script location) and validates rti_license.dat # - Uses a prebuilt Docker image with all build dependencies installed # (build it from ./Dockerfile via --build-prebuilt-image) # - Optional deletion of the prebuilt Docker image via --delete-prebuilt-image @@ -55,8 +55,10 @@ Environment variable overrides: BUILD_NUMBER= BUILD_TAG= -Required .envrc variable: - MIGRATE_PIPELINE_ROOT= +MIGRATE_PIPELINE_ROOT resolution (highest precedence first): + 1. exported MIGRATE_PIPELINE_ROOT (e.g. from a Jenkinsfile) + 2. MIGRATE_PIPELINE_ROOT set by .envrc in this directory + 3. derived from the script location (three levels up) Expected file: ${MIGRATE_PIPELINE_ROOT}/rti_license.dat @@ -259,14 +261,30 @@ build_prebuilt_image() { require_command docker -if [[ ! -f ".envrc" ]]; then - die ".envrc not found in current directory. Please create .envrc with required environment variables (e.g., MIGRATE_PIPELINE_ROOT)" +# MIGRATE_PIPELINE_ROOT resolution (highest precedence first): +# 1. exported environment variable (e.g. from a Jenkinsfile) +# 2. .envrc in this directory (if present) +# 3. derived from this script's location - the script always lives at +# /qt-migration-legatus/qt6-after/qt6-migrated-legatus, so the +# pipeline root is three levels up. This makes the script work in a +# fresh Jenkins checkout with no environment setup at all. +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +MIGRATE_PIPELINE_ROOT_DEFAULT="$(cd "${SCRIPT_DIR}/../../.." && pwd)" +PIPELINE_ROOT_EXPORTED="${MIGRATE_PIPELINE_ROOT:-}" + +if [[ -f ".envrc" ]]; then + set -a + # shellcheck disable=SC1091 + source ".envrc" + set +a fi -set -a -# shellcheck disable=SC1091 -source ".envrc" -set +a +# An explicitly exported MIGRATE_PIPELINE_ROOT (Jenkinsfile) wins over .envrc +if [[ -n "${PIPELINE_ROOT_EXPORTED}" ]]; then + MIGRATE_PIPELINE_ROOT="${PIPELINE_ROOT_EXPORTED}" +else + MIGRATE_PIPELINE_ROOT="${MIGRATE_PIPELINE_ROOT:-${MIGRATE_PIPELINE_ROOT_DEFAULT}}" +fi # Fixed configuration for the release validation-scope branch RELEASE_BUILD=ON