devops管道yaml忽略DotNetCoreCLI @ 2任务的失败测试

时间:2020-07-17 11:16:48

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

我有一个devops yaml管道,该管道运行DotNetCoreCLI @ 2任务以还原,构建和测试。

如果发生一个或多个测试失败,我希望管道继续运行并发布输出以供devops版本使用。

最初,对于失败的测试,整个管道执行将报告“ Build Failed”。在构建管道yaml顶部添加以下内容后:

  jobs:
  - job: Build
    continueOnError: true

我现在得到“部分成功构建”。

但是,当我检查管道执行摘要页面时,发现有0个工件:

enter image description here

即使测试失败,如何使管道发布?

为完整起见,完整的Yaml在下面

    stages:
- stage: Build
  jobs:
  - job: Build
    continueOnError: true

    pool:
      name: Hosted Windows 2019 with VS2019
      demands:
      - msbuild
      - visualstudio

    variables:
      solution: '**/*.sln'
      projects: '**/Interfaces.Avaloq.Presentation.AzureFunctions.csproj'
      unitTestProjects: '**/*Testing.Unit*/*.csproj'
      integrationTestProjects: '**/*Testing.Integration*/*.csproj'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Debug'

    steps:
    - script: |
    - task: DotNetCoreCLI@2
      displayName: Restore Functions
      inputs:
        command: restore
        projects: '$(projects)'
        feedsToUse: config
        nugetConfigPath: nuget.config
    - task: DotNetCoreCLI@2
      displayName: Build Functions
      inputs:
        command: build
        projects: '$(projects)'
        arguments: '--configuration $(buildConfiguration)'
    - task: DotNetCoreCLI@2
      displayName: Restore Unit Tests
      inputs:
        command: restore
        projects: '$(unitTestProjects)'
        feedsToUse: config
        nugetConfigPath: nuget.config
    - task: DotNetCoreCLI@2
      displayName: Build Unit Tests
      inputs:
        command: build
        projects: '$(unitTestProjects)'
        arguments: '--configuration $(buildConfiguration)'
    - task: DotNetCoreCLI@2
      displayName: Run Unit Tests
      inputs:
        command: 'test'
        projects: '$(unitTestProjects)'
        arguments: --filter Category!=ExcludeFromBVT
        testRunTitle: 'Unit Tests'
        feedsToUse: config
        nugetConfigPath: nuget.config
    
    - task: AzurePowerShell@4
      inputs:
        azureSubscription: 'Design Subscription (xxx)'
        ScriptType: 'InlineScript'
        Inline: |
          Set-Location $env:AGENT_WORKFOLDER
          Get-ChildItem -Recurse
        azurePowerShellVersion: 'LatestVersion'
    
    - task: DotNetCoreCLI@2
      displayName: Publish
      inputs:
        command: publish
        arguments: '--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)'
        projects: '$(projects)'
        publishWebProjects: false
        zipAfterPublish: true

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact'
      inputs:
        PathtoPublish: '$(build.artifactstagingdirectory)'
      condition: succeededOrFailed()

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: ArmTemplate'
      inputs:
        PathtoPublish: Interfaces.Avaloq.Deployment
        ArtifactName: RGDeploy

1 个答案:

答案 0 :(得分:2)

如果测试失败,请在测试步骤级别添加-。在作业级别添加它会导致下一个(从属)作业将运行。请比较一下:

  • continueOnError在工作级别: enter image description here
  • continueOnError在步骤级别: enter image description here