Skip to content

Commit a4f3c43

Browse files
[macos] check exit code in Invoke-SSHPassCommand (#8156)
1 parent b21ec05 commit a4f3c43

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

images.CI/macos/anka/Anka.Helpers.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function Invoke-AnkaCommand {
6767
[string] $Command
6868
)
6969

70-
$result = bash -c "$Command 2>&1" | Out-String
70+
$result = bash -c "$Command 2>&1"
7171
if ($LASTEXITCODE -ne 0) {
7272
Write-Error "There is an error during command execution:`n$result"
7373
exit 1

images.CI/macos/anka/CreateCleanAnkaTemplate.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ function Invoke-EnableAutoLogon {
4545

4646
$ipAddress = Get-AnkaVMIPAddress -VMName $TemplateName
4747

48+
Wait-AnkaVMSSHService -VMName $TemplateName -Seconds 30
49+
4850
Write-Host "`t[*] Enable AutoLogon"
4951
Enable-AutoLogon -HostName $ipAddress -UserName $TemplateUsername -Password $TemplatePassword
5052

images.CI/macos/anka/Service.Helpers.psm1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,12 @@ function Invoke-SSHPassCommand {
292292
"${env:SSHUSER}@${HostName}"
293293
)
294294
$sshPassOptions = $sshArg -join " "
295-
bash -c "$sshPassOptions \""$Command\"" 2>&1"
295+
$result = bash -c "$sshPassOptions \""$Command\"" 2>&1"
296+
if ($LASTEXITCODE -ne 0) {
297+
Write-Error "There is an error during command execution:`n$result"
298+
exit 1
299+
}
300+
$result
296301
}
297302

298303
function Invoke-WithRetry {
@@ -330,7 +335,10 @@ function Restart-VMSSH {
330335
[string] $HostName
331336
)
332337

333-
$command = "sudo reboot"
338+
#
339+
# https://unix.stackexchange.com/questions/58271/closing-connection-after-executing-reboot-using-ssh-command
340+
#
341+
$command = '(sleep 1 && sudo reboot &) && exit'
334342
Invoke-SSHPassCommand -HostName $HostName -Command $command
335343
}
336344

0 commit comments

Comments
 (0)