0

How I can use the value of this variable in my tests when are executed in the pipeline?

I am trying to get the values with the next configuration but with no success

Anyone with an example? or something to try?

var builder = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("appsettings.json", optional: true)
               .AddUserSecrets<ExportReportsRunnerTest>()
               .AddEnvironmentVariables();

Configuration.GetSection("DevOpsSqlConnectionString").Value
Configuration.GetValue<string>("DevOpsSqlConnectionString")

KeyVaults variable group

Thanks in advance to everybody!

Marcos Varela
  • 85
  • 1
  • 10
  • Well, an obvious problem is that DevOpsSqlConnectionString is **not** a Section. It's a key. Please refer to the documentation for .NET Core configuration.. – Daniel Mann Oct 19 '20 at 16:21
  • Yes my fail but Configuration.GetValue("DevOpsSqlConnectionString") doesn't work also – Marcos Varela Oct 19 '20 at 16:29

1 Answers1

2

If you run the tests in Visual Studio Test task in the pipeline. You can define the DevOpsSqlConnectionString parameter in the TestRunParameters section of runsettings file, or Properties section of testsettings file.

Then you can specify the overrideTestrunParameters field of Visual Studio Test task to override the parameters defined in the runsettings or testsettings file with the variables in pipeline variable group. See below description of the overrideTestrunParameters field.

Override parameters defined in the TestRunParameters section of runsettings file or Properties section of testsettings file. For example: -key1 value1 -key2 value2

enter image description here

If you use Dotnet test to run your tests in pipeline. Or the DevOpsSqlConnectionString parameter is defined in some other config files. You can use the extension task Magic Chunks to override the parameters with variables in variable group before running the tests. You can aslo check out the example in this thread.

enter image description here

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43