小编Ear*_*Gen的帖子

如何在 Azure DevOps yaml 管道中的每个循环中使用变量

我的 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)

我怎样才能做到这一点?对此有几个问题:

  1. 如何在 foreach 循环中使用 '$records.Records' 变量?使用前必须保存变量吗?如果是 - 如何保存数组?
  2. 如果不可能这样做,可能有一些方法,例如使用多个阶段、作业...等?

powershell azure-devops azure-pipelines

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

azure-devops ×1

azure-pipelines ×1

powershell ×1