mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 06:08:07 +00:00
[macos] check exit code in Invoke-SSHPassCommand (#8156)
This commit is contained in:
@@ -67,7 +67,7 @@ function Invoke-AnkaCommand {
|
|||||||
[string] $Command
|
[string] $Command
|
||||||
)
|
)
|
||||||
|
|
||||||
$result = bash -c "$Command 2>&1" | Out-String
|
$result = bash -c "$Command 2>&1"
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Error "There is an error during command execution:`n$result"
|
Write-Error "There is an error during command execution:`n$result"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ function Invoke-EnableAutoLogon {
|
|||||||
|
|
||||||
$ipAddress = Get-AnkaVMIPAddress -VMName $TemplateName
|
$ipAddress = Get-AnkaVMIPAddress -VMName $TemplateName
|
||||||
|
|
||||||
|
Wait-AnkaVMSSHService -VMName $TemplateName -Seconds 30
|
||||||
|
|
||||||
Write-Host "`t[*] Enable AutoLogon"
|
Write-Host "`t[*] Enable AutoLogon"
|
||||||
Enable-AutoLogon -HostName $ipAddress -UserName $TemplateUsername -Password $TemplatePassword
|
Enable-AutoLogon -HostName $ipAddress -UserName $TemplateUsername -Password $TemplatePassword
|
||||||
|
|
||||||
|
|||||||
@@ -292,7 +292,12 @@ function Invoke-SSHPassCommand {
|
|||||||
"${env:SSHUSER}@${HostName}"
|
"${env:SSHUSER}@${HostName}"
|
||||||
)
|
)
|
||||||
$sshPassOptions = $sshArg -join " "
|
$sshPassOptions = $sshArg -join " "
|
||||||
bash -c "$sshPassOptions \""$Command\"" 2>&1"
|
$result = bash -c "$sshPassOptions \""$Command\"" 2>&1"
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Error "There is an error during command execution:`n$result"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$result
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-WithRetry {
|
function Invoke-WithRetry {
|
||||||
@@ -330,7 +335,10 @@ function Restart-VMSSH {
|
|||||||
[string] $HostName
|
[string] $HostName
|
||||||
)
|
)
|
||||||
|
|
||||||
$command = "sudo reboot"
|
#
|
||||||
|
# https://unix.stackexchange.com/questions/58271/closing-connection-after-executing-reboot-using-ssh-command
|
||||||
|
#
|
||||||
|
$command = '(sleep 1 && sudo reboot &) && exit'
|
||||||
Invoke-SSHPassCommand -HostName $HostName -Command $command
|
Invoke-SSHPassCommand -HostName $HostName -Command $command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user