【问题标题】:Loop through dynamic template parameters in Azure devops YAML循环遍历 Azure devops YAML 中的动态模板参数
【发布时间】:2020-06-01 15:35:54
【问题描述】:

我想对作为参数传递的字符串数组执行一些操作(发布)。 问题是,这个参数是动态的:

# pipeline.yml

- job: MyJob
    pool:
      [...]
    steps:
      - pwsh: |
          $affected = ['app-one', 'app-two'] # Here I hardcoded the array but in my real code this is set dynamically
          Write-Host "##vso[task.setvariable variable=affected;isOutput=true]$affected"
        name: setAffected
        displayName: 'Settings affected'

- template: ./build.yml
  parameters:
    affected: $[ dependencies.Affected.outputs['setAffected.affected'] ] # Here I pass the array of string to the template
# build.yml

parameters:
  affected: ''

jobs:
  - job: Build
    condition: succeeded('Affected')
    dependsOn: Affected
    pool:
      [...]
    variables:
      affected: ${{ parameters.affected }}
    steps:
      - ${{each app in $(affected)}}:
          - pwsh: |
              Write-Host "${{app}}"
      - ${{each app in parameters.affected}}:
          - pwsh: |
              Write-Host "${{app}}"

${{each app in $(affected)}}${{each app in parameters.affected}} 都不起作用... 我怎样才能设法对我的每个数组项执行一些操作?

谢谢

【问题讨论】:

  • 让我猜猜。你想运行像 Nx 这样的 mororepo 应用程序吗?我有点想做同样的事情

标签: azure-devops yaml


【解决方案1】:

在模板表达式中,您可以访问参数 包含传入参数值的上下文。 此外,您可以访问变量上下文,其中包含 YAML 文件中指定的所有变量加上系统 变量。 重要的是,它没有运行时变量这样的 就像存储在管道上或在您开始运行时给出的那样。 模板扩展发生在运行的早期,所以这些变量 不可用。

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-08
    • 2021-10-14
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 2021-06-29
    • 2021-12-16
    相关资源
    最近更新 更多