复制测试工件以在多个代理上运行时如何在Azure Devops中查找单元测试dll(YAML)

时间:2020-07-07 19:15:40

标签: azure-devops continuous-integration yaml

我正在使用Azure Devops YAML构建管道来构建和测试我的SQL SSDT项目。我试图修改我的YAML代码,以便测试部分可以在多个Microsoft托管代理上运行(我已经购买了2个)。当我在单个代理上运行的第一个作业中运行VSTest任务时,它没有任何问题。但是,当我将其作为第二项工作的一部分运行时,单元测试不会运行,并出现一条错误消息,提示它找不到必需的测试文件。要完成这项工作,我需要添加一些内容吗?

非常感谢。

trigger:
  branches:
    include:
    - develop
    - stage
    - master

pr:
- master
- stage
- develop


pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'


jobs:
- job: BuildPublish
  steps:
    - task: NuGetToolInstaller@1
      inputs:
        versionSpec: '2.*'

    - task: NuGetCommand@2
      inputs:
        command: 'restore'
        restoreSolution: '$(solution)'
        feedsToUse: 'select'
        restoreDirectory: '$(Build.SourcesDirectory)/DIP_UsqlSln/packages'
    - task: VSBuild@1
      inputs:
        solution: '**/*.sln'
        msbuildArgs: '/p:USQLSDKPath=$(Build.SourcesDirectory)/DIP_UsqlSln/packages/Microsoft.Azure.DataLake.USQL.SDK.1.4.190703/build/runtime;USQLTargetType=SyntaxCheck;DataRoot=$(Build.SourcesDirectory) /p:EnableDeployment=true'## Heading ##
        createLogFile: true
        logFileVerbosity: 'detailed'

    - task: CopyFiles@2
      inputs:
        Contents: '**'
        TargetFolder: '$(build.artifactstagingdirectory)'
        CleanTargetFolder: true
        OverWrite: true
      
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'

- job: Test
  dependsOn: BuildPublish
  strategy:
    parallel: 2
  steps:
  - task: DownloadBuildArtifacts@0
    displayName: 'Download Build Artifacts'
    inputs:
      artifactName: 'drop'

  - task: VSTest@2
    inputs:
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'
      runOnlyImpactedTests: true
      runInParallel: true

1 个答案:

答案 0 :(得分:2)

在复制测试工件以在多个代理(YAML)上运行时,如何在Azure Devops中查找单元测试dll

这是因为任务DownloadBuildArtifacts的默认目标目录$(System.ArtifactsDirectory),而Visual Studio Test任务的默认 Search文件夹是{{1} }。

enter image description here

enter image description here

在构建管道中使用这两个任务时,这两个预定义变量的值不相同

$(System.DefaultWorkingDirectory)的值应为 $(System.ArtifactsDirectory)

C:\agent\_work\r1\a的值应为 $(System.DefaultWorkingDirectory)

因此,它将导致此问题,找不到必需的测试文件。

要解决此问题,我们只需要更改这两个预定义变量的默认值即可使用相同的值:

c:\agent_work\1\s

- task: DownloadBuildArtifacts@0

  displayName: 'Download Build Artifacts'

  inputs:

    artifactName: drop

    downloadPath: '$(System.DefaultWorkingDirectory)'

希望这会有所帮助。