From 1a273782aeb69c56033bef16eb79e636a6059c0e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 24 Sep 2025 13:26:38 +0200 Subject: [PATCH 1/5] transfer-to-windowsmachine: documented script Ticket: ENT-12600 Signed-off-by: Lars Erik Wik --- build-scripts/transfer-to-windowsmachine | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/build-scripts/transfer-to-windowsmachine b/build-scripts/transfer-to-windowsmachine index 3e7b8eef0..b8390af52 100644 --- a/build-scripts/transfer-to-windowsmachine +++ b/build-scripts/transfer-to-windowsmachine @@ -1,22 +1,33 @@ #!/bin/sh -x +# +# Transfer CFEngine binaries and tests to a Windows test machine +# Packages binaries and test files as ZIP archives and uploads them via SFTP +# for testing CFEngine on Windows environments -# assume `. `dirname "$0"`/functions` was executed by caller +# assume `. "$(dirname "$0")"/functions` was executed by caller test -z "$PREFIX" && exit 1 +# Configure SSH/SFTP with batch mode (no password prompts) and skip host key checking SSH="ssh -o BatchMode=yes -o StrictHostKeyChecking=no" SFTP="sftp -o BatchMode=yes -o StrictHostKeyChecking=no" +# Windows paths for 7-Zip extraction tool and Jenkins user home SEVENZIP="\"c:/program files/7-zip/7z\"" HOMEPATH="\"c:\\Users\\jenkins\"" +# Determine directory names based on whether this is a CI job or manual build if [ -z "$JOB_NAME" ]; then + # Manual build: use version and architecture in directory name DIRNAME=build-$VERSION-$ARCH TESTDIR="\"c:\\Users\\jenkins\"" else + # CI build: extract job name prefix (before first slash) DIRNAME=$(echo "${JOB_NAME}" | sed 's/\(.*\)\/.*/\1/g') TESTDIR="\"c:\\Users\\jenkins\\$DIRNAME\\tests\"" fi +# Retry wrapper function - attempts command up to 50 times +# Used for network operations that might fail temporarily MAX_TRY=50 try_run() { for _ in $(seq $MAX_TRY); do @@ -27,15 +38,18 @@ try_run() { return 1 } +# Package CFEngine binaries into a ZIP file for Windows deployment prepare_bin() { PKGD=$BASEDIR/packaging/cfengine-nova/pkg P=$PKGD/$DIRNAME rm -rf "$PKGD" mkdir -p "$P"/bin + # Copy core binaries and distribution binaries cp -a "$PREFIX/bin"/* "$P"/bin cp -a "$BASEDIR/cfengine/dist$PREFIX/bin"/* "$P"/bin + # Copy architecture-specific event DLL case "$ARCH" in x86) cp -a "$BASEDIR"/enterprise/libcfenterprise/cf.events.i686.dll "$P"/bin/cf.events.dll ;; x64) cp -a "$BASEDIR"/enterprise/libcfenterprise/cf.events.x86_64.dll "$P"/bin/cf.events.dll ;; @@ -45,14 +59,17 @@ prepare_bin() { ;; esac + # Copy Windows installer configuration file cp "$BASEDIR"/buildscripts/packaging/cfengine-nova/cfengine-nova.wxs "$P" + # Create ZIP archive of the prepared directory ( cd "$PKGD" zip -r "$DIRNAME".zip "$DIRNAME" ) || false } +# Package test suite files into a ZIP archive prepare_tests() { TESTD=$BASEDIR/core/tests ( @@ -61,19 +78,26 @@ prepare_tests() { ) || false } +# Clean up previous deployment directories on Windows machine +# Note: '|| :' ensures this doesn't fail if directories don't exist pre_put() { $SSH "$1" cmd /c "cd $HOMEPATH && rmdir /s /q $DIRNAME tests" || : } +# Upload ZIP files to Windows machine via SFTP put_zip() { echo "put $P.zip" | $SFTP "$1" echo "put $BASEDIR/core/tests/tests.zip" | $SFTP "$1" } +# Extract uploaded ZIP files on Windows machine using 7-Zip +# -y: assume Yes on all queries, -o: output directory, -r: recurse subdirectories post_put() { $SSH "$1" cmd /c "cd $HOMEPATH && $SEVENZIP x -y $DIRNAME.zip && $SEVENZIP x -y tests.zip -o$TESTDIR -r" } +# Main upload function - coordinates cleanup, upload, and extraction +# Uses try_run for each step to handle network failures gracefully put() { try_run pre_put "$1" try_run put_zip "$1" From 4f8d67d4e4fc124bd3e8d51c2717caeca2a8253f Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 24 Sep 2025 13:41:44 +0200 Subject: [PATCH 2/5] transfer-to-windowsmachine: reduced verbosity og script Signed-off-by: Lars Erik Wik --- build-scripts/transfer-to-windowsmachine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-scripts/transfer-to-windowsmachine b/build-scripts/transfer-to-windowsmachine index b8390af52..a5d4f32fe 100644 --- a/build-scripts/transfer-to-windowsmachine +++ b/build-scripts/transfer-to-windowsmachine @@ -1,4 +1,4 @@ -#!/bin/sh -x +#!/bin/sh # # Transfer CFEngine binaries and tests to a Windows test machine # Packages binaries and test files as ZIP archives and uploads them via SFTP From 98613a701a4fa427276a507790e6d22cf8662065 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 24 Sep 2025 13:41:11 +0200 Subject: [PATCH 3/5] transfer-to-windoesmachine: added log message to aid debugging Signed-off-by: Lars Erik Wik --- build-scripts/transfer-to-windowsmachine | 29 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/build-scripts/transfer-to-windowsmachine b/build-scripts/transfer-to-windowsmachine index a5d4f32fe..dd41fca27 100644 --- a/build-scripts/transfer-to-windowsmachine +++ b/build-scripts/transfer-to-windowsmachine @@ -30,11 +30,16 @@ fi # Used for network operations that might fail temporarily MAX_TRY=50 try_run() { + attempt=1 + log_debug "Starting retry wrapper for: $*" for _ in $(seq $MAX_TRY); do if "$@"; then + log_debug "Command succeeded on attempt $attempt: $*" return fi + attempt=$((attempt + 1)) done + log_error "Command failed after $MAX_TRY attempts: $*" return 1 } @@ -54,7 +59,7 @@ prepare_bin() { x86) cp -a "$BASEDIR"/enterprise/libcfenterprise/cf.events.i686.dll "$P"/bin/cf.events.dll ;; x64) cp -a "$BASEDIR"/enterprise/libcfenterprise/cf.events.x86_64.dll "$P"/bin/cf.events.dll ;; *) - echo "Unknown architecture: $ARCH" + log_error "Unknown architecture: $ARCH" exit 1 ;; esac @@ -99,7 +104,23 @@ post_put() { # Main upload function - coordinates cleanup, upload, and extraction # Uses try_run for each step to handle network failures gracefully put() { - try_run pre_put "$1" - try_run put_zip "$1" - try_run post_put "$1" + target="$1" + log_debug "Starting transfer to Windows machine: $target" + + if ! try_run pre_put "$target"; then + log_error "Failed to clean up previous deployment on $target" + return 1 + fi + + if ! try_run put_zip "$target"; then + log_error "Failed to upload files to $target" + return 1 + fi + + if ! try_run post_put "$target"; then + log_error "Failed to extract files on $target" + return 1 + fi + + log_debug "Successfully completed transfer to $target" } From a74c961a0d26f46f51940abd2864699294109e00 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 30 Sep 2025 15:17:33 +0200 Subject: [PATCH 4/5] transfer-to-windowsmachine: refactored retry wrapper - Reduced number of retries - Added sleep between retries - Added log message for each failed attempt Signed-off-by: Lars Erik Wik --- build-scripts/transfer-to-windowsmachine | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build-scripts/transfer-to-windowsmachine b/build-scripts/transfer-to-windowsmachine index dd41fca27..569d8fa39 100644 --- a/build-scripts/transfer-to-windowsmachine +++ b/build-scripts/transfer-to-windowsmachine @@ -26,18 +26,20 @@ else TESTDIR="\"c:\\Users\\jenkins\\$DIRNAME\\tests\"" fi -# Retry wrapper function - attempts command up to 50 times +# Retry wrapper function - attempts command up to 10 times # Used for network operations that might fail temporarily -MAX_TRY=50 +MAX_TRY=10 try_run() { attempt=1 log_debug "Starting retry wrapper for: $*" - for _ in $(seq $MAX_TRY); do + for i in $(seq $MAX_TRY); do if "$@"; then log_debug "Command succeeded on attempt $attempt: $*" return fi + log_debug "Attempt [$i/$MAX_TRY] failed for: $*" attempt=$((attempt + 1)) + sleep 1 done log_error "Command failed after $MAX_TRY attempts: $*" return 1 From 783b8b361390285c2e51d813f1537d03a2d371ad Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 30 Sep 2025 15:27:46 +0200 Subject: [PATCH 5/5] transfer-to-windowsmachine: use `|| true` instead of `|| :` Signed-off-by: Lars Erik Wik --- build-scripts/transfer-to-windowsmachine | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-scripts/transfer-to-windowsmachine b/build-scripts/transfer-to-windowsmachine index 569d8fa39..e6c262004 100644 --- a/build-scripts/transfer-to-windowsmachine +++ b/build-scripts/transfer-to-windowsmachine @@ -86,9 +86,9 @@ prepare_tests() { } # Clean up previous deployment directories on Windows machine -# Note: '|| :' ensures this doesn't fail if directories don't exist +# Note: '|| true' ensures this doesn't fail if directories don't exist pre_put() { - $SSH "$1" cmd /c "cd $HOMEPATH && rmdir /s /q $DIRNAME tests" || : + $SSH "$1" cmd /c "cd $HOMEPATH && rmdir /s /q $DIRNAME tests" || true } # Upload ZIP files to Windows machine via SFTP