【问题标题】:How to do a Foreach loop or Each within Azure Pipeline如何在 Azure Pipeline 中执行 Foreach 循环或 Each
【发布时间】:2023-01-17 11:34:21
【问题描述】:

我正在尝试运行查询 Azure 存储表的 Azure 管道,我可以通过从普通管道变量传入 $AppName 来做到这一点,但 id 喜欢从 yaml 文件中的应用程序列表循环多个应用程序。

我使用的 yaml 文件如下:

trigger:
  - master

variables:
  - name: AppNames
    value:
      [
        "7zip",
        "AdobeAcrobatReaderDC",
        "CitrixWorkspaceApp",
        "GoogleChrome",
        "LAPS",
        "Mimecast",
        "Nessus",
        "NotepadPlusPlus",
        "MicrosoftWvdRemoteDesktop",
      ]
  - name: baseurl
    value: $(NexusProdRepo)
  - name: genRepo
    value: $(ClientRepo)
  - name: APIKey
    value: $(PRODAPIKey)

pool:
  name: $(PoolName)
  demands:
    - agentOS -equals $(agentOS)

stages:
  - stage: Deployment
    jobs:
      - job: DeployApps
        steps:
          - script: echo "Deploying $(AppName)"
            env:
              AppName: ${{ each.value }}
        forEach: ${{ variables.AppNames }}
      - stage: QueryAzureTableStorage_Stage
        dependsOn:
          - ConnectiontoAzure
        jobs:
          - job: QueryAzureTableStorage_Job
            steps:
              - task: PowerShell@2
                displayName: "Query Azure Table Storage"
                name: "Query_Azure_Table_Storage"
                inputs:
                  targetType: filePath
                  filePath: "$(Build.SourcesDirectory)/GetAndQueryStorageTable.ps1"
                  arguments: "-StorageAccountName $(StorageAccountName) -ResourceGroupName $(ResourceGroupName) -TableName $(TableName) -AppName $(AppName)"

有没有人能够纠正我在 foreach 循环方面出错的地方,或者如果它可能的话?

【问题讨论】:

    标签: azure-devops azure-pipelines azure-yaml-pipelines


    【解决方案1】:

    从 yaml 文件中的应用程序列表循环访问多个应用程序。

    根据您的要求,我建议您可以在 YAML Pipeline 中使用 Parameters 和 Each expression。参考这个文档:Each keyword

    这是一个例子:

    parameters:
    - name: AppNames
      type: object
      default: [7zip,AdobeAcrobatReaderDC]
      
    
    
    stages:
      - ${{ each app in parameters.AppNames  }}:
        - stage: Deployment_${{ app }}
          jobs:
            - job: DeployApps
              steps:
                - script: echo "Deploying "${{ app }}""
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 2021-09-06
      • 1970-01-01
      • 2019-01-12
      • 1970-01-01
      相关资源
      最近更新 更多