繁体   English   中英

PowerShell 7 从 Azure DevOps 管道远程处理

[英]PowerShell 7 Remoting from Azure DevOps Pipeline

我们使用 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

我们添加了-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

这是Test-Parallel.ps1

$items = 1..100
 
$items | ForEach-Object -Parallel {
  Write-Host "$(Get-Date) | Sleeping for 1 second..."
  Start-Sleep 1
} -ThrottleLimit 10 

我们如何强制 PowerShell 使用我们的 Azure DevOps 管道任务运行版本 7?

在您的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 
}

然后调用Test-PipelineDeploy

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM