Reputation: 81
I'm trying to set an Azure DevOps variable in the Release pipeline during a Visual Studio Test task. From within the Visual Studio C# Test code, I want to set an ADO Release variable based on whether a test passes or not. Then I will read in this variable in the following Release task, an inline Powershell script, to execute separate tasks.
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. 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.
Is it possible to set the ADO Release variable using C# from within a Visual Studio Test task? Or can you only set variables using a Batch/Powershell/Shell script/task? If that's the case, does anyone have any suggestions on how to do this?
Upvotes: 0
Views: 937
Reputation: 76760
How to set Azure DevOps variable from Visual Studio Test task so the following inline PowerShell script can read it?
Indeed, just like jessehouwing said:
vstest redirects the console output to the trx file.
So, we need use the Logging Command to invoke a logging command.
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):
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).
Hope this helps.
Upvotes: 1