0

My current pipeline consists of 2 files: pr-validation.yml

resources:
- repo: self
queue:
  name: NonProd

variables:
  - name: 'NuGetFeedId'
    value: '11111b1d-1111-1ecb-1dc1-11f111111f11'
 
steps:
  - template: pr-validation-steps.yml
    parameters: 
      UnitTestsProjectPaths:
        - '1.Tests/1.Tests.csproj'
        - '2/2.Tests/2.Tests.csproj'
        - '3/3.Tests/3.Tests.csproj'

and actual steps in pr-validation-steps:

parameters:
- name: UnitTestsProjectPaths
  type: object
  default:
    - '1.Tests/1.Tests.csproj'
    - '2/2.Tests/2.Tests.csproj'
    - '3/3.Tests/3.Tests.csproj'

steps:
  - task: DotNetCoreCLI@2
    displayName: 'NuGet restore'
    inputs:
      command: 'restore'
      vstsFeed: '$(NuGetFeedId)'
      projects: '**/*.sln'
 
  - task: DotNetCoreCLI@2
    displayName: 'Build solution'
    inputs:
      command: 'build'
      projects: '**/*.sln'
      arguments: '--no-restore'

  - ${{ each UnitTestsProjectPath in parameters.UnitTestsProjectPaths }}:
    - task: DotNetCoreCLI@2
      displayName: 'Run unit tests in ${{ UnitTestsProjectPath }} and collect coverage'
      inputs:
        command: 'test'
        projects: '${{ UnitTestsProjectPath }}'
        arguments: '--configuration $(buildConfiguration) --collect "Code coverage" --no-restore'

As you see I'm on pre-build validation for .NET Core projects and the current fragment is about running several test projects from solution, but not all of them.

Azure DevOps is saying: 'pr-validation-steps.yml (Line: 2, Col: 1): Expected a mapping'

Basically saying that something's wrong in at the beginning of the line with a 'name' entry. I tried different syntax options but nothing worked for me.

I validated the files with Tom Austin's 'Azure Pipeline YAML Validator' and it says everything's fine.

What am I doing wrong? And in case you're using any kind of effective pipeline validator - please let me know, I really need it.

Sergey Shafiev
  • 4,205
  • 4
  • 26
  • 37

1 Answers1

2

First you have this

queue:
  name: NonProd

which I don't recognize and Azure DevOps also.

enter image description here

When you remove it you should be fine.

And speaking about validator. The only one good which I know is the one on the Azure Devops:

enter image description here

I tested this with following:

build.yml

trigger: none

pool:
  vmImage: ubuntu-latest

variables:
  - name: 'NuGetFeedId'
    value: '11111b1d-1111-1ecb-1dc1-11f111111f11'
 
steps:
  - template: pr-validation-steps.yml
    parameters: 
      UnitTestsProjectPaths:
        - '1.Tests/1.Tests.csproj'
        - '2/2.Tests/2.Tests.csproj'
        - '3/3.Tests/3.Tests.csproj'

pr-validation-steps.yml

parameters:
- name: UnitTestsProjectPaths
  type: object
  default:
    - '1.Tests/1.Tests.csproj'
    - '2/2.Tests/2.Tests.csproj'
    - '3/3.Tests/3.Tests.csproj'

steps:
  - ${{ each UnitTestsProjectPath in parameters.UnitTestsProjectPaths }}:
    - bash: echo 'Run unit tests in ${{ UnitTestsProjectPath }} and collect coverage'

And it works.

enter image description here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Removed 'queue' entry. Still the same error though. – Sergey Shafiev Jun 03 '21 at 16:48
  • 1
    Hi Krzysztof. Our admins just updated to Azure DevOps Server 2020 Update 1 and it started working fine! You were right - 'queue' is not recognized and moreover now I don't have any mapping errors after Azure DevOps upgrade. Thanks! – Sergey Shafiev Jun 07 '21 at 14:02