[英]How to set Azure DevOps variable from Visual Studio Test task so the following inline PowerShell script can read it?
I'm trying to set an Azure DevOps variable in the Release pipeline during a Visual Studio Test task.我正在尝试在 Visual Studio 测试任务期间在发布管道中设置 Azure DevOps 变量。 From within the Visual Studio C# Test code, I want to set an ADO Release variable based on whether a test passes or not.
在 Visual Studio C# 测试代码中,我想根据测试是否通过来设置 ADO Release 变量。 Then I will read in this variable in the following Release task, an inline Powershell script, to execute separate tasks.
然后我将在下面的 Release 任务中读入这个变量,一个内联的 Powershell 脚本,以执行单独的任务。
I have tried to use the Console.WriteLine("##vso[task.setvariable variable=<VARIABLE_NAME>;]<VALUE>")
in my C# Visual Studio Test code, but it does not set the variable.我曾尝试在我的 C# Visual Studio 测试代码中使用
Console.WriteLine("##vso[task.setvariable variable=<VARIABLE_NAME>;]<VALUE>")
,但它没有设置变量。 However, when I use an inline Powershell script to set the variable using Write-Host "##vso[task.setvariable variable=<VARIABLE_NAME>;]<VALUE>"
it works correctly.但是,当我使用内联 Powershell 脚本使用
Write-Host "##vso[task.setvariable variable=<VARIABLE_NAME>;]<VALUE>"
设置变量时,它可以正常工作。
Is it possible to set the ADO Release variable using C# from within a Visual Studio Test task?是否可以在 Visual Studio 测试任务中使用 C# 设置 ADO Release 变量? Or can you only set variables using a Batch/Powershell/Shell script/task?
还是只能使用 Batch/Powershell/Shell 脚本/任务设置变量? If that's the case, does anyone have any suggestions on how to do this?
如果是这种情况,是否有人对如何执行此操作有任何建议?
How to set Azure DevOps variable from Visual Studio Test task so the following inline PowerShell script can read it?
如何从 Visual Studio 测试任务中设置 Azure DevOps 变量,以便以下内联 PowerShell 脚本可以读取它?
Indeed, just like jessehouwing said:确实,就像 jessehouwing 所说:
vstest redirects the console output to the trx file.
So, we need use the Logging Command to invoke a logging command.因此,我们需要使用Logging Command来调用 logging 命令。
To resolve this issue, you can try the following method:要解决此问题,您可以尝试以下方法:
Add two inline powershell task to set the an ADO Release variable based on the results of the previous tasks (Including VS Test task):添加两个内联的 powershell 任务,根据前面任务的结果(包括 VS 测试任务)设置一个 ADO Release 变量:
Then add another powershell task to set the an ADO Release variable based when the results of all the previous task successfully (Including VS Test task).然后添加另一个 powershell 任务来设置一个 ADO Release 变量,基于之前所有任务成功(包括 VS 测试任务)的结果。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.