Dale Palmer
Dale Palmer

Reputation: 138

Secrets in Azure DevOps builds (dotnet core)

I have a number of tests in my project which are run as part of the build. Some of those tests are integration tests which need a username/password set of credentials in order to run the tests.

I want to keep these credentials out of the source code so on my local machine I have set them up as user secrets and on the server they are environment variables. The deployments are working just fine with this arrangement.

My problem is running the tests as part of the build. The tests are not being fed with any login credentials and therefore are failing with authentication issues. How do I supply these values without adding them to the appsettings.json files?

I am running a dotnet core project and have a standard Azure DevOps build template.

Thanks!

Upvotes: 7

Views: 1331

Answers (1)

Daniel Mann
Daniel Mann

Reputation: 58980

Non-secret variables declared in the build are automatically turned into environment variables on the build agent.

Secret variables are intentionally not turned into environment variables, but you can add a Command Line or Script task that's appropriate for your platform (Bash, Powershell, whatever) and set an environment variable by passing your secret in as a parameter to the script.

Upvotes: 5

Related Questions