我有託管代理的VSTS設置,我試圖運行Azure Powershell腳本以使用Runspaces異步方法調整經典雲服務的大小。這個腳本在我的本地機器上運行時工作正常。VSTS託管代理版本中的運行空間和作業Azure Powershell腳本
[hashtable]$myServices = @{}
$myServices.Add('serviceA',3)
$myServices.Add('serviceB',1)
$myServices.Add('serviceC',2)
$myServices.Add('serviceD',1)
$myServices.Add('serviceE',3)
$Throttle = 5 #threads
$ScriptBlock = {
Param (
[string]$serviceName,
[int]$instanceCount
)
Try{
$roles = Get-AzureRole -ServiceName $serviceName -Slot Production -ErrorAction Stop
foreach($role in $roles){
Write-Output 'Currently on ' + $role.RoleName
$result = Set-AzureRole -ServiceName $serviceName -Slot Production -RoleName $role.RoleName -Count $instanceCount -ErrorAction Stop
$thisRunResult = New-Object PSObject -Property @{
Service = $serviceName
Role = $role.RoleName
Description = $result.OperationDescription
Status = $result.OperationStatus
}
$RunResult += $thisRunResult
}
Return $RunResult
} Catch {
write-output "An error occurred in the script block."
write-output $_.Exception.Message
}
}
Try{
$ErrorActionPreference = "Stop"
$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, $Throttle)
$RunspacePool.Open()
$Jobs = @()
} Catch {
write-output "An error occurred while instantiating Runspaces."
write-output $_.Exception.Message
} Finally {
$ErrorActionPreference = "Continue"
}
foreach ($service in $qaServices.GetEnumerator()){
Write-Output 'Currently on ' + $service.Key
Try{
$ErrorActionPreference = "Stop"
$Job = [powershell]::Create().AddScript($ScriptBlock).AddArgument($service.Key).AddArgument($service.Value)
write-output "Line after the Job is created gets executed."
$Job.RunspacePool = $RunspacePool
$Jobs += New-Object PSObject -Property @{
RunNum = $service.Key
Pipe = $Job
Result = $Job.BeginInvoke()
}
} Catch {
write-output "An error occurred creating job."
write-output $_.Exception.Message
} Finally {
$ErrorActionPreference = "Continue"
}
}
Write-Host "Waiting.." -NoNewline
Do {
Write-Host "." -NoNewline
Start-Sleep -Seconds 1
} While ($Jobs.Result.IsCompleted -contains $false)
Write-Host "All jobs completed!"
$Results = @()
ForEach ($Job in $Jobs)
{ $Results += $Job.Pipe.EndInvoke($Job.Result)
}
$Results | Select-Object -Property Service,Role,Description,Status | Sort-Object -Property Service | Out-Host
我的Try/Catch的東西都沒有輸出日誌中的任何東西。當我在本地運行時,我得到的結果輸出就像我期待的那樣使用新的「。」。每秒一次,直到完成:
Waiting.........................All jobs completed!
本地它是幾百...因爲它需要幾分鐘的時間來擴展。在VSTS中運行時,立即返回約8個點。所以看起來沒有任何事情發生(特別是喬布斯沒有初始化),但沒有錯誤告訴我問題是什麼。提前致謝。
與提升模式? –
您使用哪個任務來運行此腳本?你可以使用設置爲「True」的「System.Debug」變量運行構建,然後共享日誌嗎? –