【问题标题】:Can't get Azure DevOps Release Pipelines to when I include Code Coverage当我包含代码覆盖率时,无法获得 Azure DevOps Release Pipelines
【发布时间】:2019-05-17 01:49:09
【问题描述】:

所以我正在尝试为新的统一构建和发布管道设置 YAML,但是当我将代码覆盖结果发布到构建时遇到问题...

当我包含代码覆盖率报告时,我得到的错误是:

Job Job1: Step Download_Code Coverage Report_870 has an invalid name. Valid names may only contain alphanumeric characters and '_' and may not start with a number.

当我这样设置时,它可以工作,但我没有得到代码覆盖率结果:

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
  - master

variables:
  buildConfiguration: 'Release'
  system.debug: true

stages:
  - stage: BuildAndDeploy
    displayName: Test
    jobs:
      - job: Quality
        displayName: Get Test Coverage and Code Quality
        pool:
          vmImage: 'ubuntu-latest'
        steps:
          # Install the latest version of the dotnet sdk
          - task: DotNetCoreInstaller@0
            displayName: 'Use .NET Core sdk 2.2.103'
            inputs:
              version: 2.2.103

          - script: dotnet build --configuration $(buildConfiguration)
            displayName: 'dotnet build $(buildConfiguration)'

          - script: dotnet test --configuration $(buildConfiguration) --logger trx --no-build
            displayName: 'dotnet test --configuration $(buildConfiguration) --logger trx --no-build'

          - task: PublishTestResults@2
            inputs:
              testRunner: VSTest
              testResultsFiles: 'test/**/*.trx'

          - task: DotNetCoreCLI@2
            displayName: Package Artifact
            inputs:
              command: 'publish'
              arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
              zipAfterPublish: True
              publishWebProjects: true
              feedsToUse: 'select'
              versioningScheme: 'off'

          - task: PublishPipelineArtifact@0
            inputs:
              artifactName: 'FakeApiServer'
              targetPath: '$(Build.ArtifactStagingDirectory)/FakeApi.Server.AspNetCore.zip'

  - stage: DeployTest
    dependsOn: BuildAndDeploy
    condition: and(succeeded(), not(eq(variables['Build.SourceBranch'], 'refs/heads/master')))
    displayName: Deploy To Test
    jobs:
    - deployment: DeployToTest
      environment: Testing
      pool:
        vmImage: 'ubuntu-latest'
      strategy:
        runOnce:
          deploy:
            steps:
            - task: DownloadPipelineArtifact@1
              inputs:
                buildType: 'current'
                artifactName: 'FakeApiServer'
                targetPath: '$(System.ArtifactsDirectory)'

            - task: AzureRmWebAppDeployment@4
              displayName: Deploy to https://fake-api-test.azurewebsites.com
              inputs:
                ConnectionType: 'AzureRM'
                azureSubscription: 'Fake API Personal Azure Subscription'
                appType: 'webApp'
                WebAppName: 'fake-api-test'
                Package: $(System.ArtifactsDirectory)/*.zip
                enableCustomDeployment: true
                DeploymentType: 'zipDeploy'

  - stage: DeployProd
    dependsOn: BuildAndDeploy
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
    displayName: Deploy To Prod
    jobs:
    - deployment: DeployToProd
      environment: Production
      pool:
        vmImage: 'ubuntu-latest'
      strategy:
        runOnce:
          deploy:
            steps:
            - task: DownloadPipelineArtifact@1
              inputs:
                buildType: 'current'
                artifactName: 'FakeApiServer'
                targetPath: '$(System.ArtifactsDirectory)'

            - task: AzureRmWebAppDeployment@4
              displayName: Deploy to https://fake-api.azurewebsites.com
              inputs:
                ConnectionType: 'AzureRM'
                azureSubscription: 'Fake API Personal Azure Subscription'
                appType: 'webApp'
                WebAppName: 'fake-api'
                Package: $(System.ArtifactsDirectory)/*.zip
                enableCustomDeployment: true
                DeploymentType: 'zipDeploy'

但是当我包含运行和报告代码覆盖率时,部署阶段会失败:

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
  - master

variables:
  buildConfiguration: 'Release'
  system.debug: true

stages:
  - stage: BuildAndDeploy
    displayName: Test
    jobs:
      - job: Quality
        displayName: Get Test Coverage and Code Quality
        pool:
          vmImage: 'ubuntu-latest'
        steps:
          # Install the latest version of the dotnet sdk
          - task: DotNetCoreInstaller@0
            displayName: 'Use .NET Core sdk 2.2.103'
            inputs:
              version: 2.2.103

          - script: dotnet tool install --global coverlet.console
            displayName: 'Install coverlet'

          - script: dotnet tool install -g dotnet-reportgenerator-globaltool
            displayName: 'install reportgenerator'

          - script: dotnet build --configuration $(buildConfiguration)
            displayName: 'dotnet build $(buildConfiguration)'

          - script: dotnet test --configuration $(buildConfiguration) /p:Exclude="[xunit*]*" /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover,cobertura\" --logger trx --no-build
            displayName: 'dotnet test --configuration $(buildConfiguration) /p:Exclude="[xunit*]*" /p:CollectCoverage=true /p:CoverletOutputFormat="opencover,cobertura" --logger trx --no-build'

          - script: reportgenerator -reports:test/**/coverage.cobertura.xml -targetdir:coveragereport -reporttypes:"HtmlInline_AzurePipelines;Cobertura"
            displayName: 'reportgenerator -reports:test/**/coverage.cobertura.xml -targetdir:coveragereport -reporttypes:"HtmlInline_AzurePipelines;Cobertura"'

          - task: PublishTestResults@2
            inputs:
              testRunner: VSTest
              testResultsFiles: 'test/**/*.trx'

          - task: PublishCodeCoverageResults@1
            displayName: 'Publish code coverage'
            inputs:
              codeCoverageTool: Cobertura
              summaryFileLocation: '$(Build.SourcesDirectory)/coveragereport/Cobertura.xml'

          - task: DotNetCoreCLI@2
            displayName: Package Artifact
            inputs:
              command: 'publish'
              arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
              zipAfterPublish: True
              publishWebProjects: true
              feedsToUse: 'select'
              versioningScheme: 'off'

          - task: PublishPipelineArtifact@0
            inputs:
              artifactName: 'FakeApiServer'
              targetPath: '$(Build.ArtifactStagingDirectory)/FakeApi.Server.AspNetCore.zip'

  - stage: DeployTest
    dependsOn: BuildAndDeploy
    condition: and(succeeded(), not(eq(variables['Build.SourceBranch'], 'refs/heads/master')))
    displayName: Deploy To Test
    jobs:
    - deployment: DeployToTest
      environment: Testing
      pool:
        vmImage: 'ubuntu-latest'
      strategy:
        runOnce:
          deploy:
            steps:
            - task: DownloadPipelineArtifact@1
              inputs:
                buildType: 'current'
                artifactName: 'FakeApiServer'
                targetPath: '$(System.ArtifactsDirectory)'

            - task: AzureRmWebAppDeployment@4
              displayName: Deploy to https://fake-api-test.azurewebsites.com
              inputs:
                ConnectionType: 'AzureRM'
                azureSubscription: 'Fake API Personal Azure Subscription'
                appType: 'webApp'
                WebAppName: 'fake-api-test'
                Package: $(System.ArtifactsDirectory)/*.zip
                enableCustomDeployment: true
                DeploymentType: 'zipDeploy'

  - stage: DeployProd
    dependsOn: BuildAndDeploy
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
    displayName: Deploy To Prod
    jobs:
    - deployment: DeployToProd
      environment: Production
      pool:
        vmImage: 'ubuntu-latest'
      strategy:
        runOnce:
          deploy:
            steps:
            - task: DownloadPipelineArtifact@1
              inputs:
                buildType: 'current'
                artifactName: 'FakeApiServer'
                targetPath: '$(System.ArtifactsDirectory)'

            - task: AzureRmWebAppDeployment@4
              displayName: Deploy to https://fake-api.azurewebsites.com
              inputs:
                ConnectionType: 'AzureRM'
                azureSubscription: 'Fake API Personal Azure Subscription'
                appType: 'webApp'
                WebAppName: 'fake-api'
                Package: $(System.ArtifactsDirectory)/*.zip
                enableCustomDeployment: true
                DeploymentType: 'zipDeploy'

同样,我得到的错误是:

Job Job1: Step Download_Code Coverage Report_870 has an invalid name. Valid names may only contain alphanumeric characters and '_' and may not start with a number.

我参加了 Build 2019,并在他们的展位上与 Azure DevOps 人员交谈,他们似乎认为这可能是系统中的一个错误,但我仍然没有收到他们的回复,所以我想我会看到如果这里有人有任何想法。

真正奇怪的部分是我从不告诉它下载代码覆盖率报告工件......它只是决定自己下载它,并在它到达之前失败下载我定义的管道工件步骤。

【问题讨论】:

标签: azure-devops


【解决方案1】:

您可以试用 ReportGenerator 扩展:https://marketplace.visualstudio.com/items?itemName=Palmmedia.reportgenerator(至少可以节省一些构建时间,因为您不需要在构建期间安装它)

我今天也遇到了几个构建问题,似乎与使用 vmImage 设置为“ubuntu-latest”有关。

我看到的情况是,在某些构建中,文件系统将如下所示:

/home/vsts/agents/2.150.3/d:\a/1/s/

应该是这样的:

/home/vsts/work/1/s/

切换到“Ubuntu 16.04”后,它似乎恢复了正常。

【讨论】:

    【解决方案2】:

    我有同样的问题,但我认为它与部署作业有关,当我使用具有相同步骤的标准作业时 - 问题没有出现。我还注意到我的部署作业在服务器代理上运行,即使 pool: vmImage: ubuntu-latest 已配置

    【讨论】:

      猜你喜欢
      • 2021-06-04
      • 2021-01-17
      • 2020-02-13
      • 2022-01-12
      • 2021-05-25
      • 2020-07-08
      • 2019-10-21
      • 2016-10-19
      • 2020-01-12
      相关资源
      最近更新 更多