Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 461
Dale Palmer Avatar asked Dec 06 '18 14:12

Dale Palmer


People also ask

Where can I store secrets in Azure DevOps?

Search for vault and select the Azure Key Vault task. Select your Azure subscription and then select Authorize. Select your Key vault from the dropdown menu, and then select Add to add the task to your YAML pipeline. The Make secrets available to whole job feature is not supported in Azure DevOps Server 2019 and 2020.

How do you use secret variables in Azure pipeline?

To use the secret variable in the task , you need to map the secret variable to a new environment variable as shown below. So the environment variable Pwd is mapped to the value of secret variable Password. and then you can use this variable in the script. So instead of using $env:Password , you will use $env:Pwd.


1 Answers

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.

like image 132
Daniel Mann Avatar answered Oct 20 '22 04:10

Daniel Mann