azure-devopsyamlazure-pipelinesazure-pipelines-yaml

Yaml number type not being recognised as a integer


Got a little problem which I am sure a Yaml guru will quickly solve for me.

We have a set of parameters thus on a Azure pipeline Yaml file

parameters:
  - name: customers
    type: object
    default:
      - name: module
        type: string
        default: Warmup
      - name: timeout
        type: number
        default: 20

      - name: module
        type: string
        default: Sidebar
      - name: timeout
        type: number
        default: 15

and so on, further down the yaml file we have a loop

- ${{ each section in parameters.customers }}:
  - task: VSTest@3
    displayName: 'Testing - ${{ section.module }} '
    inputs:
      testAssemblyVer2: 'C:\Code\Release\net7.0\CodeRegression.dll'
      searchFolder: 'C:\Code\Release\net7.0\'
      testFiltercriteria: 'TestCategory=${{ section.name }}'
      testRunTitle: 'Regression ${{ section.name }}'
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
    continueOnError: true
    condition: succeededOrFailed()
    timeoutInMinutes: ${{ section.timeout }}

But I get an error

enter image description here

And validate shows this

enter image description here

Any thoughts on where I am going wrong please?


Solution

  • Please note there's no such thing as schemas for the Azure pipelines parameters. You can define a parameter as object, but there's no way to enforce a specific structure and types for each property.

    Instead of:

    parameters:
      - name: customers
        type: object
        default:
          - name: module        
            type: string
            default: Warmup
          - name: timeout       
            type: number
            default: 20
    
          - name: module        
            type: string
            default: Sidebar
          - name: timeout       
            type: number
            default: 15
    

    You can define an array with 2 elements like this:

    parameters:
      - name: customers
        type: object
        default:
          - module: Warmup
            timeout: 20
    
          - module: Sidebar
            timeout: 15
    

    I'm not completely sure if only 2 properties (module and timeout) are required in your specific scenario for each element, but obviously more can be added if required.

    Using parameters.customers:

    - ${{ each section in parameters.customers }}:
      - task: VSTest@3
        displayName: 'Testing - ${{ section.module }} '
        inputs:
          testAssemblyVer2: 'C:\Code\Release\net7.0\CodeRegression.dll'
          searchFolder: 'C:\Code\Release\net7.0\'
          testFiltercriteria: 'TestCategory=${{ section.module }}'
          testRunTitle: 'Regression ${{ section.module }}'
          platform: '$(buildPlatform)'
          configuration: '$(buildConfiguration)'
        continueOnError: true
        condition: succeededOrFailed()
        timeoutInMinutes: ${{ section.timeout }}