簡體   English   中英

如何創建 Azure Devops 的數組變量

[英]How to create Array Variable of Azure Devops

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 任務

如何在 Main Pipeline abc 中定義值,以便它可以作為參數傳遞給模板文件?

什么數據類型的參數可以作為數組使用?

Azure 管道沒有數組參數類型。 您可以使用object類型並對其進行迭代。

用戶定義的變量沒有類型 變量是一個字符串,句點。 您不能定義包含項目數組的變量。

但是,您可以添加分隔列表,然后split列表。

IE

variables:
  foo: a,b,c,d

- ${{ each x in split(variables.foo, ',') }}:
  - script: echo ${{ x }}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM