question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing variables and secrets from VSTS

See original GitHub issue

Description

I have several secrets stored in KeyVault. Unfortunately I cannot find a way to pass parameters to my test run via VSTS

Documentation says that Keyvault secrets can only be supplied via VSTS variables - fair enough - but how do I actually do this? All the information I can find on web seems outdated or doesn’t work.

For example - consider RunSettings file:

<RunSettings>
    <TestRunParameters>  
		<Parameter name="webAppUrl" value="http://localhost" /> 
		<Parameter name="webAppUserName" />
		<Parameter name="webAppPassword" />
  </TestRunParameters> 
</RunSettings>

I tried passing values for last 2 parameters via cmd line as follow:

vsts.console MyTest.dll /Settings:vsts.runsettings -- -webAppUserName foo
vsts.console MyTest.dll /Settings:vsts.runsettings -- webAppUserName=foo
dotnet test -s vsts.runsettings -- -webAppUserName foo
dotnet test -s vsts.runsettings -- webAppUserName=foo

but this has no effect - the webAppUserName value remains null (I can see a value for webAppUrl, so I know my code is right!)

I’ve also tried both the VSTS “dotnet test” task as well as the “VsTest” task from my VSTS 2017 build. The VsTest provides a Override test run parameters setting - and as per the tooltip, I tried: -webAppUserName user -webAppPassword somethingSecret

Again - no effect!

Originally I used xUnit and had exactly the same issue - i.e. coudn’t figure out a way to pass parameters via VSTS - so I tried MSTest, but same issue.

Going back to my original issue of injecting KeyVault secrets Locally via VS Studio I was able to just do the following from my test:

var config = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", true, true)
                ...
                .AddAzureKeyVault(...)

Unfortunately, when run via VSTS, the test runner just hangs (i.e. I had to stop it after several minutes) with no log output for test step if I use either

.AddAzureKeyVault(…) or .AddEnvironmentVariables()

So I tried using VSTS Variable Groups - and linking that to KeyVault. However, keyvault secrets are not accessible via environment variables (using Enviroment.GetEnvironmentVariable(…) directly from C#) - so that’s no good. They say you can only pass these to tasks via VSTS variables…hence my problem!

##Aside: Even if I could use environment variables, it’s not optimal because when using .AddAzureKeyVault() I can supply a custom IKeyVaultSecretManager to, for example, replace a special delimiter with the ‘:’ character - this means that I can nest my json config values - e.g. if I had this in my config file: { “A” : { “B” : “somevalue” } }

then using normal configuration builder I can access the above via config[“A:B”]. Unfortunately KeyVault doesn’t like the “:” character - so you have to replace it with something like “–” and then use a custom IKeyVaultSecretManager to replace “–” with “:”

Please help! All I wanted for Christmas was not to put my KeyVault secrets into Git… but still use this from within my tests… surely I’m missing something??

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
JohnGalt1717commented, Jun 26, 2018

Closing for what reason? You didn’t answer the issue.

Override what run parameters? Where? Do you mean in the “Override test run parameters” field of VSTS?

And how exactly will those get passed? As environment variables? Or something else?

This should be a sample that is right in the .NET core documentation AND in the vsts documentation. This is automated testing 101: How do you pass variables per run and use those to configure your tests? There is 0 documentation on this.

And the link says this only works for MSTest, thus no xunit etc.

This should be part of the ConfigurationBuilder in .NET Core and it should be able to pull this out.

2reactions
Adebeercommented, Jun 27, 2018

I agree with @JohnGalt1717 . The link you provided is not relevant - it’s dated 2015. The issue is trying to pass parameters to tests in VS2017 and .net core test projects. We’re trying to write end to end and integration tests - but without the ability to pass parameters this is not feasible. Can you please provide a solution to this fundamental issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

azure pipelines - VSTS secrets as environment variables
In the build, I run a command prompt task to run set -- e.g. show me all the environment variables. Those marked as...
Read more >
Set secret variables - Azure Pipelines
Never pass secrets on the command line. Instead, we suggest that you map your secrets into environment variables. We never mask substrings of ......
Read more >
Expose VSTS secrets as environment variables with this one ...
Secret variables are not exposed as environment variables, but can only be passed as arguments to our build steps.
Read more >
Build variables marked as secrets are not available ...
For example if I create a build pipeline variable called `TARGET_SYSTEM_PASSWORD` and mark it as secret, I can refer to it using the ......
Read more >
Secret Variables do not work for Deployment Jobs.
If I create a simple pipeline with nothing but a deployment stage and attempt to pass a secret variable to that stage, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found