1
- #! /bin/sh -x
1
+ #! /bin/sh
2
+ #
3
+ # Transfer CFEngine binaries and tests to a Windows test machine
4
+ # Packages binaries and test files as ZIP archives and uploads them via SFTP
5
+ # for testing CFEngine on Windows environments
2
6
3
- # assume `. ` dirname "$0"` /functions` was executed by caller
7
+ # assume `. "$( dirname "$0")" /functions` was executed by caller
4
8
test -z " $PREFIX " && exit 1
5
9
10
+ # Configure SSH/SFTP with batch mode (no password prompts) and skip host key checking
6
11
SSH=" ssh -o BatchMode=yes -o StrictHostKeyChecking=no"
7
12
SFTP=" sftp -o BatchMode=yes -o StrictHostKeyChecking=no"
8
13
14
+ # Windows paths for 7-Zip extraction tool and Jenkins user home
9
15
SEVENZIP=" \" c:/program files/7-zip/7z\" "
10
16
HOMEPATH=" \" c:\\ Users\\ jenkins\" "
11
17
18
+ # Determine directory names based on whether this is a CI job or manual build
12
19
if [ -z " $JOB_NAME " ]; then
20
+ # Manual build: use version and architecture in directory name
13
21
DIRNAME=build-$VERSION -$ARCH
14
22
TESTDIR=" \" c:\\ Users\\ jenkins\" "
15
23
else
24
+ # CI build: extract job name prefix (before first slash)
16
25
DIRNAME=$( echo " ${JOB_NAME} " | sed ' s/\(.*\)\/.*/\1/g' )
17
26
TESTDIR=" \" c:\\ Users\\ jenkins\\ $DIRNAME \\ tests\" "
18
27
fi
19
28
20
- MAX_TRY=50
29
+ # Retry wrapper function - attempts command up to 10 times
30
+ # Used for network operations that might fail temporarily
31
+ MAX_TRY=10
21
32
try_run () {
22
- for _ in $( seq $MAX_TRY ) ; do
33
+ attempt=1
34
+ log_debug " Starting retry wrapper for: $* "
35
+ for i in $( seq $MAX_TRY ) ; do
23
36
if " $@ " ; then
37
+ log_debug " Command succeeded on attempt $attempt : $* "
24
38
return
25
39
fi
40
+ log_debug " Attempt [$i /$MAX_TRY ] failed for: $* "
41
+ attempt=$(( attempt + 1 ))
42
+ sleep 1
26
43
done
44
+ log_error " Command failed after $MAX_TRY attempts: $* "
27
45
return 1
28
46
}
29
47
48
+ # Package CFEngine binaries into a ZIP file for Windows deployment
30
49
prepare_bin () {
31
50
PKGD=$BASEDIR /packaging/cfengine-nova/pkg
32
51
P=$PKGD /$DIRNAME
33
52
rm -rf " $PKGD "
34
53
mkdir -p " $P " /bin
35
54
55
+ # Copy core binaries and distribution binaries
36
56
cp -a " $PREFIX /bin" /* " $P " /bin
37
57
cp -a " $BASEDIR /cfengine/dist$PREFIX /bin" /* " $P " /bin
38
58
59
+ # Copy architecture-specific event DLL
39
60
case " $ARCH " in
40
61
x86) cp -a " $BASEDIR " /enterprise/libcfenterprise/cf.events.i686.dll " $P " /bin/cf.events.dll ;;
41
62
x64) cp -a " $BASEDIR " /enterprise/libcfenterprise/cf.events.x86_64.dll " $P " /bin/cf.events.dll ;;
42
63
* )
43
- echo " Unknown architecture: $ARCH "
64
+ log_error " Unknown architecture: $ARCH "
44
65
exit 1
45
66
;;
46
67
esac
47
68
69
+ # Copy Windows installer configuration file
48
70
cp " $BASEDIR " /buildscripts/packaging/cfengine-nova/cfengine-nova.wxs " $P "
49
71
72
+ # Create ZIP archive of the prepared directory
50
73
(
51
74
cd " $PKGD "
52
75
zip -r " $DIRNAME " .zip " $DIRNAME "
53
76
) || false
54
77
}
55
78
79
+ # Package test suite files into a ZIP archive
56
80
prepare_tests () {
57
81
TESTD=$BASEDIR /core/tests
58
82
(
@@ -61,21 +85,44 @@ prepare_tests() {
61
85
) || false
62
86
}
63
87
88
+ # Clean up previous deployment directories on Windows machine
89
+ # Note: '|| true' ensures this doesn't fail if directories don't exist
64
90
pre_put () {
65
- $SSH " $1 " cmd /c " cd $HOMEPATH && rmdir /s /q $DIRNAME tests" || :
91
+ $SSH " $1 " cmd /c " cd $HOMEPATH && rmdir /s /q $DIRNAME tests" || true
66
92
}
67
93
94
+ # Upload ZIP files to Windows machine via SFTP
68
95
put_zip () {
69
96
echo " put $P .zip" | $SFTP " $1 "
70
97
echo " put $BASEDIR /core/tests/tests.zip" | $SFTP " $1 "
71
98
}
72
99
100
+ # Extract uploaded ZIP files on Windows machine using 7-Zip
101
+ # -y: assume Yes on all queries, -o: output directory, -r: recurse subdirectories
73
102
post_put () {
74
103
$SSH " $1 " cmd /c " cd $HOMEPATH && $SEVENZIP x -y $DIRNAME .zip && $SEVENZIP x -y tests.zip -o$TESTDIR -r"
75
104
}
76
105
106
+ # Main upload function - coordinates cleanup, upload, and extraction
107
+ # Uses try_run for each step to handle network failures gracefully
77
108
put () {
78
- try_run pre_put " $1 "
79
- try_run put_zip " $1 "
80
- try_run post_put " $1 "
109
+ target=" $1 "
110
+ log_debug " Starting transfer to Windows machine: $target "
111
+
112
+ if ! try_run pre_put " $target " ; then
113
+ log_error " Failed to clean up previous deployment on $target "
114
+ return 1
115
+ fi
116
+
117
+ if ! try_run put_zip " $target " ; then
118
+ log_error " Failed to upload files to $target "
119
+ return 1
120
+ fi
121
+
122
+ if ! try_run post_put " $target " ; then
123
+ log_error " Failed to extract files on $target "
124
+ return 1
125
+ fi
126
+
127
+ log_debug " Successfully completed transfer to $target "
81
128
}
0 commit comments