mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2026-01-07 18:47:18 +08:00
Merge pull request #1873 from andy-mishechkin/v-andmis/Implement_to_stop_and_to_rename_failed_vm
Implement additional feature for stopping and renaming the unstable VMs in case of failure
This commit is contained in:
@@ -48,12 +48,23 @@ Import-Module $PSScriptRoot\helpers.psm1 -DisableNameChecking
|
||||
# Connection to a vCenter Server system
|
||||
Connect-VCServer
|
||||
|
||||
try
|
||||
{
|
||||
Get-VM $VMName | Move-VM -Datastore $TargetDataStore -ErrorAction Stop
|
||||
Write-Host "VM has been moved successfully to target datastore '$TargetDataStore'"
|
||||
$vm = Get-VM $VMName
|
||||
|
||||
if ($env:AGENT_JOBSTATUS -eq 'Failed') {
|
||||
try {
|
||||
if($vm.PowerState -ne "PoweredOff") {
|
||||
Stop-VM -VM $vm -Confirm:$false -ErrorAction Stop
|
||||
}
|
||||
Set-VM -VM $vm -Name "${VMName}_failed" -Confirm:$false -ErrorAction Stop
|
||||
Write-Host "VM has been successfully powered off and renamed to [${VMName}_failed]"
|
||||
} catch {
|
||||
Write-Host "##vso[task.LogIssue type=error;]Failed to power off and rename VM '$VMName'"
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
try {
|
||||
Move-VM -Vm $vm -Datastore $TargetDataStore -ErrorAction Stop
|
||||
Write-Host "VM has been moved successfully to target datastore '$TargetDataStore'"
|
||||
} catch {
|
||||
Write-Host "##vso[task.LogIssue type=error;]Failed to move VM '$VMName' to target datastore '$TargetDataStore'"
|
||||
}
|
||||
Reference in New Issue
Block a user