[英]PowerShell 7 Remoting from Azure DevOps Pipeline
We were using Azure DevOps Pipelines and PowerShell Remoting to execute PS1 scripts:我们使用 Azure DevOps Pipelines 和 PowerShell Remoting 来执行 PS1 脚本:
trigger: none
jobs:
- job: PSRemoting
timeoutInMinutes: 5760
pool:
name: 'DevOps-Agent2-VM'
steps:
- checkout: none
- task: PowerShellOnTargetMachines@3
displayName: 'PSRemoting'
inputs:
Machines: '$(VM-PublicIP)'
UserName: '$(VM-UserName)'
UserPassword: '$(VM-Password)'
InlineScript: |
. C:\Scripts\Test-Parallel.ps1
We have added -parallel
feature that requires PowerShell 7 and our scripts are failing now:我们添加了-parallel
功能,需要 PowerShell 7 并且我们的脚本现在失败了:
2022-11-02T13:37:18.3246154Z ForEach-Object : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ & 'C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ForEach-Object ...med parameters.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
At C:\Scripts\Test-Parallel.ps1:3 char:10
+ $items | ForEach-Object -Parallel {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [ForEach-Object], ParentContainsErrorRecordExcep
tion
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ForEachObjectCo
mmand
##[error]Non-Zero exit code: '1' for ComputerName: 'VM1'
##[error]Atleast one remote job failed. Consult logs for more details. ErrorCodes(s): 'RemoteDeployer_NonZeroExitCode'
##[section]Finishing: PSRemoting
Here is Test-Parallel.ps1
:这是Test-Parallel.ps1
:
$items = 1..100
$items | ForEach-Object -Parallel {
Write-Host "$(Get-Date) | Sleeping for 1 second..."
Start-Sleep 1
} -ThrottleLimit 10
How can we force PowerShell to run version 7 with our Azure DevOps Pipeline task?我们如何强制 PowerShell 使用我们的 Azure DevOps 管道任务运行版本 7?
Try this in your Test-Parallel.ps1
script:在您的Test-Parallel.ps1
脚本中试试这个:
workflow Test-PipelineDeploy {
$items = 1..100
foreach -parallel ($item in $items) {
Write-Host "$(Get-Date) | Sleeping for 1 second..."
Start-Sleep 1
} -ThrottleLimit 10
}
Then call Test-PipelineDeploy
然后调用Test-PipelineDeploy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.