'Expected a mapping' 在 .NET Core 应用程序构建的 Azure DevOps 管道模板中使用 'parameters' 部分时出现语法错误
'Expected a mapping' syntax error when using 'parameters' section in Azure DevOps pipeline templates for .NET Core app build
我当前的管道由 2 个文件组成:
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'
和 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'
如您所见,我正在对 .NET Core 项目进行预构建验证,当前片段是关于 运行 来自解决方案的几个测试项目,但不是全部。
Azure DevOps 说:
'pr-validation-steps.yml (Line: 2, Col: 1): Expected a mapping'
基本上是说 'name' 条目行的开头有问题。我尝试了不同的语法选项,但没有任何效果。
我用 Tom Austin 的 'Azure Pipeline YAML Validator' 验证了文件,它说一切都很好。
我做错了什么?如果您正在使用任何一种有效的管道验证器 - 请告诉我,我真的需要它。
首先你有这个
queue:
name: NonProd
我不认识,还有 Azure DevOps。
当你删除它时你应该没问题。
并谈到验证器。我知道的唯一一个好东西是 Azure Devops 上的那个:
我用以下方法对此进行了测试:
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-验证-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'
而且有效。
我当前的管道由 2 个文件组成: 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'
和 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'
如您所见,我正在对 .NET Core 项目进行预构建验证,当前片段是关于 运行 来自解决方案的几个测试项目,但不是全部。
Azure DevOps 说: 'pr-validation-steps.yml (Line: 2, Col: 1): Expected a mapping'
基本上是说 'name' 条目行的开头有问题。我尝试了不同的语法选项,但没有任何效果。
我用 Tom Austin 的 'Azure Pipeline YAML Validator' 验证了文件,它说一切都很好。
我做错了什么?如果您正在使用任何一种有效的管道验证器 - 请告诉我,我真的需要它。
首先你有这个
queue:
name: NonProd
我不认识,还有 Azure DevOps。
当你删除它时你应该没问题。
并谈到验证器。我知道的唯一一个好东西是 Azure Devops 上的那个:
我用以下方法对此进行了测试:
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-验证-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'
而且有效。