簡體   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