2

在 Azure Devops(本地)服务器中运行“远程计算机上的 Powershell”任务时,我们始终会看到执行中的 30 秒暂停。

这使得即使是非常简单的远程远程脚本调用也至少需要 30 秒才能完成。

将任务更改为普通的 powershell 任务并手动设置 PSSession 并发出完全相同的 Invoke-Command 运行得更快。

所以问题是,这是 Azure Devops 服务器中的一个错误,还是我们需要为 Powershell 在远程机器任务上做一些额外的配置,以使其性能更好?我们没有尝试调整任何东西——只是使用了默认的任务配置。

Azure Devops 服务器版本为 2019 Update 1。代理已更新到最新版本。

“远程计算机上的 Powershell”Azure Devops 任务的输出:

2019-10-10T04:51:03.4296728Z ##[section]Starting: <hidden> - Stop site
2019-10-10T04:51:03.4727773Z ==============================================================================
2019-10-10T04:51:03.4728808Z Task         : PowerShell on target machines
2019-10-10T04:51:03.4728850Z Description  : Execute PowerShell scripts on remote machines using PSSession and Invoke-Command for remoting
2019-10-10T04:51:03.4728886Z Version      : 3.1.2
2019-10-10T04:51:03.4728935Z Author       : Microsoft Corporation
2019-10-10T04:51:03.4728970Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/powershell-on-target-machines
2019-10-10T04:51:03.4729006Z ==============================================================================
2019-10-10T04:51:08.6710628Z PSSession created for Machines:'<hidden>'
2019-10-10T04:51:08.9207041Z ================================================ <hidden> ================================================
2019-10-10T04:51:38.9317626Z ================================================ <hidden> ================================================
2019-10-10T04:51:38.9325165Z ##[command]& 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\Users\<hidden>\AppData\Local\Temp\f228e8e1-f90a-4263-89cd-55320f5ad80b.ps1'"
2019-10-10T04:51:38.9630832Z 
2019-10-10T04:51:39.0526046Z Script execution succeeded for ComputerName: '<hidden>'
2019-10-10T04:51:39.3236823Z ##[section]Finishing: <hidden> - Stop site

OBS 从 2019-10-10T04:51:08.9207041Z 到 2019-10-10T04:51:38.9317626Z 的 30 秒暂停。我们在所有针对机器任务的 Powershell 中都看到了这种暂停。

更改为普通的 Powershell 任务并手动设置 PSSession 将使脚本运行得更快。我们这样实现它:

$password = ConvertTo-SecureString "$(PASSWORD)" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("$(USER)", $password)
$session = New-PSSession -ComputerName $(SERVER) -Credential $cred -UseSSL

Invoke-Command -Session $session -ScriptBlock { `
  Copy-Item "C:\Users\<HIDDEN>\Documents\app_offline.htm" `
  "$(DEPLOY_PATH)\app_offline.htm" `
}
4

0 回答 0