我当前的管道由 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(行:2,列:1):预期映射'
基本上是说在“名称”条目的行开头出现了问题。我尝试了不同的语法选项,但没有任何效果。
我用 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-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'
而且它有效。
关于azure - 在用于 .NET Core 应用程序构建的 Azure DevOps 管道模板中使用 'parameters' 部分时出现“预期映射”语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67822955/