https://medium.com/tech-start/looping-a-task-in-azure-devops-ac07a68a5556
以下是我的主要管道:
pool:
vmImage: 'windows-latest'
parameters:
- name: environment
displayName: 'Select Environment To Deploy'
type: string
values:
- A1
- A2
default: A1
variables:
- name: abc
value: 'firm20 firm201' # How to declare Array variable?
stages:
- stage: stage01
displayName: 'Deploy in Environment '
jobs:
- template: templates/test_task_for.yml # Template reference
# parameters:
# list: $(abc)
下面是我的模板管道:
parameters:
- name: list
type: ??? #What type here pls?
default: [] #? is this correct?
jobs:
- job: connectxyz
displayName: 'Connect'
steps:
- ${{each mc in variables.abc}}: # parameters.list
- task: CmdLine@2
inputs:
script: 'echo Write your commands here. ${{mc}}'
我需要多次运行 CmdLine@2 任务
如何定义主管道 abc 中的值,以便可以将其作为参数传递给模板文件?
参数的数据类型是什么,以便它可以作为数组工作?
最佳答案
Azure Pipelines 没有数组参数类型。您可以使用 object
类型并对其进行迭代。
用户定义的变量不输入。变量是字符串、句点。您不能定义包含项目数组的变量。
但是,您可以添加分隔列表,然后分割
该列表。
即
variables:
foo: a,b,c,d
- ${{ each x in split(variables.foo, ',') }}:
- script: echo ${{ x }}
关于azure - 如何创建Azure Devops的数组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73951254/