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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With