azure - 在用于 .NET Core 应用程序构建的 Azure DevOps 管道模板中使用 'parameters' 部分时出现“预期映射”语法错误

标签 azure .net-core azure-devops azure-pipelines azure-pipelines-yaml

我当前的管道由 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 也不认识。

enter image description here

当你删除它时,你应该没问题。

谈论验证器。我所知道的唯一一件好事是 Azure DevOps 上的一件好事:

enter image description here

我用以下方法对此进行了测试:

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'

而且它有效。

enter image description here

关于azure - 在用于 .NET Core 应用程序构建的 Azure DevOps 管道模板中使用 'parameters' 部分时出现“预期映射”语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67822955/

相关文章:

c# - 为什么 JsonConverter 忽略 WriteIndented 选项?

azure-devops - Azure DevOps yaml 管道表达式未评估

ios - 无法加载证书,Xcode 构建无法安装证书(VSTS/Azure DevOps、YAML Pipeline)

azure - 如何在 Powershell 中使用 Azure Function 应用程序写入文件

.net-core - System.MissingMethodException 单元测试

azure - 我们可以设置多个指向 Azure Blob 存储的 CNAME 记录吗?

nuget - 如何在最新的.NET Core工具中实现版本自动递增?

testing - 关于新迭代的 TFS 测试计划的管理

angular - 如何设置我在用户流 AZ AD B2C 中看到的屏幕

python - 将 Azure Blob 存储中的新 CSV 加载到 SQL DB