简体   繁体   English

通过多个代理将变量从一个 Visual Studio 测试任务传递到 Azure Pipeline 中的另一个

[英]Pass Variables from one Visual Studio Test Task to Another in Azure Pipeline through multiple agents

I have couple of unit tests in the project which are dependent to one another.我在项目中有几个单元测试,它们相互依赖。 After one test runs, i will capture the output, wait for it to synchronize in another system and perform another test using the output of the first test.一个测试运行后,我将捕获输出,等待它在另一个系统中同步并使用第一个测试的输出执行另一个测试。 I am trying to achieve this using azure pipeline.我正在尝试使用 azure 管道来实现这一点。 I created 3 Agent Jobs -, in Job A, I am running Unit Test1 and creating a output variable which am passing to a variable in Job C, Job B is an agent less server to delay for 1 minute in between these 2 agents.我创建了 3 个代理作业 - 在作业 A 中,我正在运行单元测试 1 并创建一个输出变量,该变量将传递给作业 C 中的一个变量,作业 B 是一个无代理服务器,在这两个代理之间延迟 1 分钟。 I have used overrideTestrunParameters: '-sauce2 $(sauce5)' to override the parameters for second test but i got below error, while passing the parameters to the second agent task.我已经使用 overrideTestrunParameters: '-sauce2 $(sauce5)' 来覆盖第二个测试的参数,但在将参数传递给第二个代理任务时出现以下错误。

[warning]Unable to parse the override run parameters string: -sauce2 crushed tomatoes [警告] 无法解析覆盖运行参数字符串:-sauce2 碎番茄

[error]SetupPhase.Run : Exception occurred during the updation of run settings: System.FormatException: Error encountered while overriding test run parameters. [错误]SetupPhase.Run:运行设置更新期间发生异常:System.FormatException:覆盖测试运行参数时遇到错误。 Please check the test run parameteres provided.请检查提供的测试运行参数。

at Microsoft.VisualStudio.TestService.SettingsManager.OverrideParamsSettingsProcessor.GetOverrideParameters(String overrdeParametersString) at Microsoft.VisualStudio.TestService.SettingsManager.OverrideParamsSettingsProcessor.UpdateSettingsWithParameters(XDocument settings) at Microsoft.VisualStudio.TestService.SettingsManager.CommonSettingsManager.UpdateCommonSettings(InputDataContract inputDataContract, SettingsModifier settingsModifier) at Microsoft.VisualStudio.TestService.SettingsManager.SettingsManager.UpdateSettingsAsRequired(InputDataContract inputDataContract) at MS.VS.TestService.VstestConsoleAdapter.SetupPhase.Run(VstestConsoleRunContext testRunContext, CancellationToken cancellationToken)在 Microsoft.VisualStudio.TestService.SettingsManager.OverrideParamsSettingsProcessor.GetOverrideParameters(String overrdeParametersString) 在 Microsoft.VisualStudio.TestService.SettingsManager.OverrideParamsSettingsProcessor.UpdateSettingsWithParameters(XDocument settings) 在 Microsoft.VisualStudio.TestService.SettingsManager.CommonSettingsManager.UpdateCommonSettings(InputDataContract inputDataifierd ) 在 Microsoft.VisualStudio.TestService.SettingsManager.SettingsManager.UpdateSettingsAsRequired(InputDataContract inputDataContract) 在 MS.VS.TestService.VstestConsoleAdapter.SetupPhase.Run(VstestConsoleRunContext testRunContext, CancellationToken cancelationToken)

[error]Settings updation failed with error: Error encountered while overriding test run parameters. [错误]设置更新失败,错误:覆盖测试运行参数时遇到错误。 Please check the test run parameteres provided.请检查提供的测试运行参数。

TestRunParameters:测试运行参数:

 <RunSettings>
 <TestRunParameters>
    <Parameter name="sauce" value="chilly" />
    <Parameter name="sauce1" value="chilly1" />
    <Parameter name="sauce2" value="chilly2" />
</TestRunParameters>

UnitTests:单元测试:

[Test]
    public void UnitTest1()
    {
        string sauce = TestContext.Parameters["sauce"];
        string sauce1 = TestContext.Parameters["sauce1"];
        TestContext.Progress.WriteLine(sauce);
        TestContext.Progress.WriteLine(sauce1);
        //creating outpute variable in azure
        TestContext.Progress.WriteLine("##vso[task.setvariable variable=sauce4;Secret=false;isOutput=true;]crushed tomatoes");
    }

    [Test]
    public void UnitTest2()
    {
        string sauce2 = TestContext.Parameters["sauce2"];
        TestContext.Progress.WriteLine($"sauce2: {sauce2}");
    }

Azure.yaml pipeline: Azure.yaml 管道:

jobs:


- job: A
pool:
  name: New Agent Pool
  demands: 
  - msbuild
  - visualstudio
  - vstest

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'
  sauce: 'tomato'
  sauce1: 'pepper'

steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(solution)'

- 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
  displayName: 'Unit Test1'
  inputs:
    testAssemblyVer2: |
      **\$(BuildConfiguration)\*Test*.dll
      !**\obj\**
    testFiltercriteria: 'Name=UnitTest1'
    runSettingsFile: SeleniumTest.ABC/Test.runsettings
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    overrideTestrunParameters: '-sauce $(sauce)'
  name: 'OutputVar'

  - job: B
dependsOn: 
  - A 
pool: server
steps:
- task: Delay@1
  inputs:
    delayForMinutes: '1'

  - job: C
dependsOn: 
  - A 
  - B
pool:
  name: New Agent Pool
  demands: 
  - msbuild
  - visualstudio
  - vstest

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'
  sauce2: $[dependencies.A.outputs['outputVar.sauce4']]

steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(solution)'

- 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: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.      
      Write-Host run time value
      Write-Host sauce2 = $(sauce2)

- task: VSTest@2
  displayName: 'Unit Test2'
  inputs:
    testAssemblyVer2: |
      **\$(BuildConfiguration)\*Test*.dll
      !**\obj\**
    testFiltercriteria: 'Name=UnitTest2'
    runSettingsFile: SeleniumTest.ABC/Test.runsettings
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    overrideTestrunParameters: '-sauce2 $(sauce2)'
  condition: succeededOrFailed()

Screenshots:截图: 在此处输入图片说明

I could see that in Powershell task new run time parameter is printed, but its failing in VS Test Task.我可以看到在 Powershell 任务中打印了新的运行时参数,但在 VS 测试任务中失败了。 Can some one advise me how to capture run time variables in VSTest Task and pass to another VSTest Task in Azure pipelines.有人可以建议我如何在 VSTest 任务中捕获运行时变量并将其传递给 Azure 管道中的另一个 VSTest 任务。

The output variable is successfully past from job A to job C, for the powershell task can print out the new variable $(source2) .输出变量成功地从作业 A 传递到作业 C,因为 powershell 任务可以打印出新变量$(source2)

The problem came from the overrideTestrunParameters: '-sauce2 $(sauce2)' of the vstest task in job C. $(sauce2) is evaluate to crushed tomatoes without quotes "".问题来自作业 C 中 vstest 任务的overrideTestrunParameters: '-sauce2 $(sauce2)'$(sauce2)被评估为没有引号“”的crushed tomatoes

Please try wrapping $(sauce2) in double quotes:请尝试将$(sauce2)用双引号括起来:

overrideTestrunParameters: '-sauce2 "$(sauce2)"'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 C# 从 Visual Studio 传递管道变量 - How to Pass Pipeline Variables from Visual Studio using C# 您可以在一台计算机上安装多个Visual Studio 2015测试代理吗? - Can you install multiple Visual Studio 2015 Test Agents on a single computer? 如何从 Visual Studio 测试任务中设置 Azure DevOps 变量,以便以下内联 PowerShell 脚本可以读取它? - How to set Azure DevOps variable from Visual Studio Test task so the following inline PowerShell script can read it? 多个 Visual Studio 解决方案在一个 Azure Function 服务中 - Multiple Visual Studio Solutions in one Azure Function service 如何在测试任务中分析 azure devops 管道中的超时 - How can I analyze a timeout in a azure devops pipeline in test task 测试多个列的值,从 Visual Studio 访问 SQL - Test a value of multiple columns, Access SQL from Visual Studio 如何将2个变量从一种形式传递给另一种形式? - How can I pass 2 variables from one form to another? Response.Redirect从一个Web项目转到Visual Studio中的另一个Web项目 - Response.Redirect from one web project to another in Visual Studio 将代码从一个解决方案复制到另一个 c# (Visual Studio) - Copy code from one solution to another c # (Visual Studio) 如何从另一个执行一项Azure功能并在本地进行测试? - How to execute one azure function from another and test locally?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM