将任务拆分为单独的作业后未找到测试

No tests found after splitting tasks out into separate jobs

我正在尝试通过将一些任务拆分成单独的作业来重构我的构建管道以实现可扩展性。

以下完美运行,找到测试并且 运行 没有问题。

stages:
  - stage: build_test_publish
    displayName: Build
    pool:
      vmImage: "windows-latest"
    variables:
      solution: "**/SolutionName.sln"
      buildPlatform: "Any CPU"
      buildConfiguration: "Release"
    jobs:
      - job: build_publish_artifacts
        displayName: "Build, test and publish artifacts"
        steps:
          - task: NuGetToolInstaller@1
          - task: NuGetCommand@2
            inputs:
              command: "restore"
              restoreSolution: "**/*.sln"
              feedsToUse: "select"
              vstsFeed: "xxx"

          - task: VSBuild@1
            inputs:
              solution: "$(solution)"
              msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
              platform: "$(buildPlatform)"
              configuration: "$(buildConfiguration)"

          - task: VSTest@2
            inputs:
              platform: '$(buildPlatform)'
              configuration: '$(buildConfiguration)'
              runInParallel: false
              codeCoverageEnabled: true
              testAssemblyVer2: |
                 **\*test*.dll
                 !**\ProjectName.IntegrationTests.dll
                 !**\*TestAdapter.dll
                 !**\obj\**
              searchFolder: '$(System.DefaultWorkingDirectory)'

然而,在像下面这样拆分之后,我得到以下输出,其中没有找到测试。

stages:
  - stage: build_test_publish
    displayName: Build, test and publish artifacts
    pool:
      vmImage: "windows-latest"
    variables:
      solution: "**/SolutionName.sln"
      buildPlatform: "Any CPU"
      buildConfiguration: "Release"
    jobs: 
      - job: build
        displayName: "Build"
        steps:
          - task: NuGetToolInstaller@1
          - task: NuGetCommand@2
            inputs:
              command: "restore"
              restoreSolution: "**/*.sln"
              feedsToUse: "select"
              vstsFeed: "xxx"
          - task: VSBuild@1
            inputs:
              solution: "$(solution)"
              msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
              platform: "$(buildPlatform)"
              configuration: "$(buildConfiguration)"
                

      - job: test
        displayName: Run unit tests
        dependsOn: build
        steps:
          - task: VSTest@2
            inputs:
              platform: '$(buildPlatform)'
              configuration: '$(buildConfiguration)'
              runInParallel: false
              codeCoverageEnabled: true
              testAssemblyVer2: |
                 **\*test*.dll
                 !**\ProjectName.IntegrationTests.dll
                 !**\*TestAdapter.dll
                 !**\obj\**
              searchFolder: '$(System.DefaultWorkingDirectory)'
Starting: VSTest
==============================================================================
Task         : Visual Studio Test
Description  : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
Version      : 2.170.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/vstest
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : D:\a\s
Action when minimum tests threshold not met : donothing
Minimum tests expected to be run: 0
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation with version [16.0,17.0).
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : true
Diagnostics enabled : false
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
Source filter: **\*test*.dll,!**\ProjectName.IntegrationTests.dll,!**\*TestAdapter.dll,!**\obj\**
##[warning]No test sources found matching the given filter '**\*test*.dll,!**\ProjectName.IntegrationTests.dll,!**\*TestAdapter.dll,!**\obj\**'
Finishing: VSTest

为什么会发生这种情况,我应该改变或重新思考什么?

**编辑 似乎是因为每个作业都使用自己的代理来 运行 其作业中的任务。

https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started/key-pipelines-concepts?view=azure-devops

我仍然想知道这样的事情是否可行,以便使用不同的环境变量开始测试 运行s

DLL 由

制作
          - task: VSBuild@1
            inputs:
              solution: "$(solution)"
              msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
              platform: "$(buildPlatform)"
              configuration: "$(buildConfiguration)"

不在开箱即用的作业之间共享。在幕后拆分任务 运行 VSBuild 和 VSTask 在不同的机器上。这样做没有多大意义 - 我的意思是拆分这两项任务。

但是,如果您仍想这样做,则需要 publish artifact and download it in next job