admin管理员组

文章数量:1398771

I have a yml pipeline and I would like to have a dict variable like the 'files' variable below

variables:
- template: ../../ci-cd/ado_variables/vars.yml
- template: ../../ci-cd/ado_variables/${{ parameters.vnet }}_vars.yml
- name: files
  value:
    aaa: aaa.zip
    bbb: bbbb.zip

unfortunately when I use this format Azure devops complains:

/ci-cd/ado_pipelines/run_ingestion.yml (Line: 76, Col: 5): A mapping was not expected

is there a way to achieve what i want? and access this variable later in the pipeline? Many thanks

I have a yml pipeline and I would like to have a dict variable like the 'files' variable below

variables:
- template: ../../ci-cd/ado_variables/vars.yml
- template: ../../ci-cd/ado_variables/${{ parameters.vnet }}_vars.yml
- name: files
  value:
    aaa: aaa.zip
    bbb: bbbb.zip

unfortunately when I use this format Azure devops complains:

/ci-cd/ado_pipelines/run_ingestion.yml (Line: 76, Col: 5): A mapping was not expected

is there a way to achieve what i want? and access this variable later in the pipeline? Many thanks

Share Improve this question asked Mar 13 at 10:57 Alberto BAlberto B 5701 gold badge5 silver badges17 bronze badges 1
  • No, you can not use complex data type in Variables. All variables are strings, refer this docs learn.microsoft/en-us/azure/devops/pipelines/process/…. You can use Parameters with complex data type or using compressed string and then deserialize it when using Variables – wenbo - Finding Job Commented Mar 14 at 3:38
Add a comment  | 

2 Answers 2

Reset to default 1

That is a complex task to suggest something without pipeline sources. However, you may consider using parameters from this example (or use as an array): https://learn.microsoft/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#each-keyword

parameters:
- name: listOfFiles
  type: object
  default:
  - key: 'apple'
    name: 'apple.txt'
  - lemon: 'lemon'
    name: 'lemon.txt'
steps:
- ${{ each file in parameters.listOfFiles }} :
  - script: echo ${{ file.key }} ${{ file.name }}

Currently, Azure DevOps doesn't support such variable. As a workaround, you can use parameter. Refer to the example below.

parameters:
  - name: filesExample
    type: object
    default:
      aaa: aaa.zip
      bbb: bbb.zip
steps:
  - script: |
      echo 'the value of aaa: ${{parameters.filesExample.aaa}}'
      echo 'the value of bbb: ${{parameters.filesExample.bbb}}'

Result:

本文标签: Have a dict type variable in Azure yml pipelinesStack Overflow