私はホストされたエージェントとVSTSセットアップを持っており、Azure Powershellスクリプトを実行してRunspaces asyncメソッドを使って古典的なクラウドサービスのサイズを変更しようとしています。このスクリプトは、ローカルマシンで実行するとうまく動作します。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
私の試してみると、ログには何も出力されません。これをローカルで実行すると、新しい "。"で期待したような出力が得られます。それが完了するまで毎秒:
Waiting.........................All jobs completed!
ローカルには数百のものがあります。 VSTSで実行すると、約8ドットがすぐに返されます。実際には何も起きていないようです(具体的には、ジョブが初期化されていない)が、問題が何であるか教えても間違いありません。前もって感謝します。
昇順モードのRAN? –
このスクリプトを実行するために使用するタスクはどれですか? "System.Debug"変数を "True"に設定してビルドを実行してログを共有できますか? –