azure - 如何创建Azure Devops的数组变量

标签 azure azure-devops azure-pipelines pipeline

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/

相关文章:

import - 如何将 wiki 移动到 Azure DevOps 中的其他项目

azure - 需要在电子邮件通知中发送发布测试结果图表

.net - 为什么 Visual Studio 在 Azure DevOps checkin 时排除 BIN 和 OBJ 文件夹

linux - 在 Linux 上从 Ansible 连接 winrm 模块

rest - 使用 Windows Azure 服务总线 REST API 以编程方式在主题中创建订阅

sql - 如何在 SQL 中写出/转换 YYYY-MM-DD 为 "Month, DD, YYYY"

azure-devops - 通过 VSTS CI/CD 升级 Azure Service Fabric 时出错

c# - CloudTableClient客户端超时

azure - 将 Azure DevOps 组织从一个订阅移动到另一个订阅

rest - 如何从 VSTS 下载所有附件?