gpt4 book ai didi

azure-devops - 在 Azure devops YAML 中循环动态模板参数

转载 作者:行者123 更新时间:2023-12-05 06:16:18 24 4
gpt4 key购买 nike

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

# 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}} 都不起作用...我如何设法对我的每个数组项执行一些操作?

谢谢

最佳答案

Within a template expression, you have access to the parameters context that contains the values of parameters passed in. Additionally, you have access to the variables context that contains all the variables specified in the YAML file plus the system variables. Importantly, it doesn't have runtime variables such as those stored on the pipeline or given when you start a run. Template expansion happens very early in the run, so those variables aren't available.

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

关于azure-devops - 在 Azure devops YAML 中循环动态模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62135666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com