简体   繁体   English

如何从 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?

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.

相关问题 如何在测试任务中分析 azure devops 管道中的超时 - How can I analyze a timeout in a azure devops pipeline in test task 如何从 Visual Studio (C#) 启动 PowerShell 脚本 - How to launch PowerShell script from Visual Studio (C#) 通过多个代理将变量从一个 Visual Studio 测试任务传递到 Azure Pipeline 中的另一个 - Pass Variables from one Visual Studio Test Task to Another in Azure Pipeline through multiple agents Azure Devops Visual Studio 测试任务无法发现具有 TestCaseSource 属性的 Nunit 测试 - Azure Devops Visual Studio Tests task cannot discover Nunit tests with the TestCaseSource attribute 如何从 azure 作业批处理中的任务返回错误,以便可以重新激活任务? - How can I return error from a task in azure job batch so task may be reactivated? 如何将变量传递给脚本任务SSIS,Visual Studio 2010,C# - How to pass Variable to script task SSIS, Visual Studio 2010, c# 如何打包 PowerShell Binary Cmdlet 从 Azure DevOps Gallery 安装 - How to pack PowerShell Binary Cmdlet to install from Azure DevOps Gallery Mac 上的 Visual Studio 2022 Azure Devops 存储库 - Visual Studio 2022 on Mac Azure Devops Repository Visual Studio 2019,使用 Azure Devops 上的运行设置进行 UI 测试视频捕获,wmv 0 字节 - Visual Studio 2019, UI test video capture using runsettings on Azure Devops, wmv 0 bytes 如果在Visual Studio和C#中,我可以在内联中设置断点吗? - Can I set a breakpoint in an inline if in Visual Studio and C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM