Ear*_*Gen 6 powershell azure-devops azure-pipelines
我的 Azure DevOps 管道中有一个 PowerShell 脚本:
- task: PowerShell@2
displayName: Get_records
inputs:
targetType: 'inline'
script: |
<...>
$records.Records
Run Code Online (Sandbox Code Playgroud)
$records.Records是一些包含记录数组的变量。我需要以这种方式使用这些数据:对于该数组中的每条记录,我需要在一项作业中执行多项任务。像这样的东西:
stages:
- stage: stage_1
jobs:
- job: Job_1
- task: PowerShell@2
displayName: Get_records
inputs:
targetType: 'inline'
script: |
<..getting this records..>
$records.Records
- ${{each records in variables.records.Records}}:
- task: not_powershell
displayName: name1
inputs:
AsyncOperation: true
MaxAsyncWaitTime: '60'
- task: not_powershell
displayName: name2
inputs:
AsyncOperation: true
MaxAsyncWaitTime: '60'
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?对此有几个问题:
Vin*_*ren 14
不,你不能。它仅适用于参数,不适用于变量:
这是因为:
解决方法
您不能在管道中循环动态数组变量;但您可以这样做的一个地方是在任务中,例如在powershell 脚本中:
- task: PowerShell@2
displayName: Loop Over Records
inputs:
targetType: 'inline'
script: |
# first, get the records
ForEach ($record in $records.Records) {
# do something with $record
}
Run Code Online (Sandbox Code Playgroud)
这不像管道循环那么强大,可以使用所有不同类型的非 powershell 任务,但它可能是循环该数组的唯一方法。
| 归档时间: |
|
| 查看次数: |
21430 次 |
| 最近记录: |