Secrets in Azure DevOps builds (dotnet core) - .net-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!

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.

Related

Configuring nuget for visual-studio-generated docker build

Visual Studio now generates Dockerfile for dotnet projects, and we are using it (with slight tweaks) for our continuous integration.
However that Dockerfile does not have any provision for configuring nuget. It even only copies the .csproj file from context before running dotnet restore to avoid re-running that step during development.
But our project requires some modules from internal, password-protected repository, so I need to provide package sources and credentials to the dotnet restore command inside.
What is the best current practice for injecting a (environment-specific) nuget configuration?
This is documented here: https://github.com/dotnet/dotnet-docker/blob/main/documentation/scenarios/nuget-credentials.md.
To summarize, there are a variety of ways in which this can be done:
Use a multi-stage build to protect nuget.config that contains hard-coded credentials. Only recommended if you ensure that credentials are kept out of source code control and the nuget.config file is ephemeral.
Passing secrets by file with BuildKit. This is similar to the previous option but makes use of Dockerfile secrets to provide access to the nuget.config file.
Use environment variables in nuget.config. In this scenario, the nuget.config file would reference environment variables for its credential values. The environment variables would then be set by the build machine when executing a docker build.
Use the Azure Artifact Credential Provider. This is only possible if you make use of Azure Artifacts for your package feed.
No matter which option you choose, be sure that credentials are never stored within an image layer that is published.

Dot net core how do I utilise appsettings.[envname].json when deploying via azure devops?

I'm using dot net core 3.0.1, for some reason I'm finding it really hard to work out how to utilize my appsettings.production.json when deploying using azure devops pipelines. My pipeline is as follows;
Restore > Build > Package > Publish Artefact > Azure App Service Deploy
The application is hosted fine but I cant see where/how I tell it to use/apply the production transform.
Dot net core how do I utilise appsettings.[envname].json when deploying via azure devops?
There is difference between Web Deploy/Visual Studio and Deploy Azure App Service in Azure devops publish task.
In order to use/apply the production transform during the Azure devops release, you will need to add variables to the release task and pass into the task the json file in question for variable substitution.
When in "Deploy Azure App Service" release task you should see a "File Transforms and Variable Substitution" section. In here you will supply the path to the json file you want to swap variable values:
Then you can add the json property you want to modify as a variable. In my case the connection string. Which will look like the following:
Check the document File transforms and variable substitution reference for some more details.
Hope this helps.

Dotnet core ignores ASPNETCORE_ENVIRONMENT variable

I created a simple webapi project with dotnet core.
I'm trying to set the running environment using the ASPNETCORE_ENVIRONMENT system variable.
C:\devel\apps\webapi>set ASPNETCORE_ENVIRONMENT=Production
C:\devel\apps\webapi>echo %ASPNETCORE_ENVIRONMENT%
Production
C:\devel\apps\webapi>dotnet run
Using launch settings from C:\devel\apps\webapi\Properties\launchSettings.json...
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\SSCARANO\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Hosting environment: Development
Content root path: C:\devel\apps\webapi
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
I tried opening a different console, and also setting it logged in as administrator, but the app is always running on Development mode.
I saw this (https://stackoverflow.com/a/40102470/47633) related question, but I'm not using IIS
I suspect that the issue you're encountering is that the ASPNETCORE_ENVIRONMENT variable is defined in the C:\devel\apps\webapi\Properties\launchSettings.json file.
The way dotnet run works is it loads this file and finds the first profile which commandName is project, and uses it to run the application. There's a high chance, if you haven't made any changes to that file, that the environmentVariables section of that profile contains the ASPNETCORE_ENVIRONMENT variable set to Development.
You have 2 options if you want to run the app in Production mode:
change the existing profile and set the variable to Production, meaning every time you execute dotnet run, it's going to run the app in production mode; or
add a new profile where the ASPNETCORE_ENVIRONMENT variable is set to Production. You can then use it if you execute dotnet run --launch-profile <name-of-your-new-profile>
The problem is how you have set the environment variable. On the command line you don't need the quotes, so you should instead have this:
C:\> set ASPNETCORE_ENVIRONMENT=Production
C:\> echo %ASPNETCORE_ENVIRONMENT%
Production

How to install FitNesse on application server as war/ear

Fitnesse download page only has option for standalone.jar and this is also what the instructions are for. Is it somehow possible to install FitNesse on a separate app server, such as Tomcat? There's not directly any war/ear to download, but can I bundle one somehow?
I'm experimenting with acceptance testing frameworks and need to run the tests on a very specific test environment, and thus require a possibility for installing on an already running app container where the tests are executed. Changes for getting even java executable from command line in this environment are slim, and if possible, the process would take probably months to realize.
I do not believe it is possible, but even if you were to get the wiki running inside an app server, a test run would still try to start a new java process (by starting the java executable) so you still need access to that executable.
But does the test environment really need to be in the app server? I usually use FitNesse to test an application from the outside: the test framework makes remote (http) calls to an application running in an app server, but it does not run in that same app server itself.

Run Automated Tests After Team Build On Physical Environment

We are trying to automate our tests but we have some problems.
Our solution has 7 projects, one of them is WCF server and one of them is Windows Forms project. Others are helper projects.
We created a test plan and test cases. We runned our test cases with action recording and converted manual tests to Coded UI test. After that, we assoiciate our coded ui test with test case.
We defined a new build. This new build deploys WCF server to IIS and transform app.config and copy client application files to a folder.
We setted up test controller and test agent at same build machine.
I wonder what need we to do to automate our build and test?
How our build trig automated test?
Because of VMWare infrastructure we can't use Lab Management.
I solved this problem myself.
I used msdeploy to deploy WCF service
I created a database project and used VSDBCMD tool
I installed test controller and test agent my build server
I created test settings for automated tests and configured to use this agent
I attached my coded ui test with test case
Then it is ok :)

Resources