Skip to content

Commit 254deda

Browse files
committed
CI: add loggin to install-windows-updates
Also adds a TODO about simplifying the double loop used to check whether all updates have been installed.
1 parent fc1eca3 commit 254deda

File tree

1 file changed

+22
-11
lines changed
  • ci/tasks/install-windows-updates

1 file changed

+22
-11
lines changed

ci/tasks/install-windows-updates/run.sh

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ function start_powershell_command() {
3131
function get_powershell_pid_exit_code() {
3232
local powershell_pid="${1}"
3333

34-
echo "Getting exit code for ${powershell_pid}" >&2
35-
# -X blocks until the guest process exits
36-
json_out=$(
37-
govc guest.ps \
38-
-vm.ipath="${vm_ipath}" \
39-
-l="${vm_username}:${vm_password}" \
40-
-X -json \
41-
-p="${powershell_pid}"
42-
)
43-
echo "${json_out}" >&2
44-
echo "${json_out}" | jq '.processInfo[0].exitCode'
34+
if [[ -z "${exit_code}" ]]; then
35+
echo "Provide PID was blank: '${powershell_pid}" >&2
36+
else
37+
echo "Getting exit code for '${powershell_pid}'" >&2
38+
# -X blocks until the guest process exits
39+
json_out=$(
40+
govc guest.ps \
41+
-vm.ipath="${vm_ipath}" \
42+
-l="${vm_username}:${vm_password}" \
43+
-X -json \
44+
-p="${powershell_pid}"
45+
)
46+
echo "JSON response for 'guest.ps': ${json_out}" >&2
47+
echo "${json_out}" | jq '.processInfo[0].exitCode'
48+
fi
4549
}
4650

4751
function download_remote_file() {
@@ -113,6 +117,13 @@ run_powershell_command_with_logging 'Install-Module -Name PSWindowsUpdate -Minim
113117
updates_remaining=$(get_windows_updates_remaining)
114118
echo "Initial Windows Updates to install: ${updates_remaining}" >&2
115119

120+
# TODO: rewrite as a single loop:
121+
# install updates
122+
# wait for VM to reboot
123+
# wait for vmware tools to be available
124+
# (re)get updates-remaining
125+
# => if remaining == 0; break
126+
116127
while [[ ${updates_remaining} -ne 0 ]]; do
117128
set +e # ignore unreachable agent if the vm just went down for reboot
118129
run_powershell_command_with_logging "Install-WindowsUpdate -AcceptAll -AutoReboot"

0 commit comments

Comments
 (0)