[英]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)' 来覆盖第二个测试的参数,但在将参数传递给第二个代理任务时出现以下错误。
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)
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()
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.