How to set azure-web-app-service application settings for node.js app via deployment - node.js

Is it possible to set azure app service application settings (especially env variables) via deployment?
We are using local git repositories to deploy our NodeJS application to different azure appservices.
There are several environment variables required to run the application. I'd like to know if there is a way to insert those automatically while deploying the application so I do not have to set them manually for each application.
If its possible how does azure handles changes in the environment settings if I changed a variable afterwords? For example if I have sensitive data that I have to enter after deployment directly into the env variable?
Here's an example. Variables: Name=InitialValue
VAR_1=Test1234
VAR_2=Hello World
USERNAME=
PASSWORD=
USERNAME AND PASSWORD need to be empty an filled afterwords directly via azure portal. Now I redeploy. What happens to my USERNAME and PASSWORD entries? What happens if I change the value of VAR_1? In this case I'd like to have the environment variable changed.

In azure app service the environment variables can be set via Application Settings > App Settings.
It has a 'key-value' format where you can enter the variable name and its value.
Then in the code you can read them as "process.env.Username " and so on.

Related

How to list Azure app service read-only environment variables

Is there a way to list out the read-only app service environment variables for an Azure app service? I need the built-in variables listed here in the first section: https://learn.microsoft.com/en-us/azure/app-service/reference-app-settings?tabs=kudu%2Cdotnet. For example, the value of WEBSITE_HOSTNAME or SERVER_PORT
I do not need to set custom variables in Configuration => Application Settings. I need an easy list of all environment variables.
When we deploy Azure Web App Service by default app will be set with read-only Environment Variables.
We can override the existing Environment variables in Configuration => App Settings section of the deployed Web App.
We can check the environment variables in Azure Portal KUDU Console.
Path to open KUDU Console
Open Azure Portal => Select your App Service => Under Development Tools select Advanced Tools => Click on Go
Way 1 :
In KUDU Console Click on Environment, list of default and the Variables you created in App settings will be seen.
Way 2 :
In KUDU Console Click on Debug console and select CMD , run printenv command.

Azure App Service configuration settings (environment variable) does not work

I created an environment variable in Azure App Service. However, I'm not able to pick the value from Azure while it is published.
So I added it to the appsettings.json, and it works.
My question would be, if I add an environment variable in Azure configuration settings, shall I add it in the appsettings.json as well, or is having it in the Azure environment settings enough?
When I navigate to
https://your-web-name.scm.azurewebsites.net/Env.cshtml
I can clearly see the variable is present there. Why is this not being picked up in the code? Am I doing something wrong?
appSettings["MailKitPassword"] <-- This is not being picked up, so I have to hard-code it.
In order to retrieve it you should use Environment.GetEnvironmentVariable("APPSETTING_MailKitPassword")
As Thiago Mentioned, you need to use GetEnvironmentVariable method to retrieve the AppSettings values,
so your code should be
Environment.GetEnvironmentVariable("APPSETTING_MailKitPassword")
However i would recommend you to store the passwords in Azure KeyVault.

Azure Web App for Containers not setting Environment Variables

I have a docker image being deployed from Azure Container Registry. Everything works fine except that I expect to be able to
see environment variables being passed to my running docker image from the Application Settings configured in the portal. It is a Node app accessing environment variables with process.env.VariableName.
As an example its says here
https://blogs.msdn.microsoft.com/waws/2017/09/08/things-you-should-know-web-apps-and-linux/#SetEnvVar …
"App Settings are injected into your app as environment variables at runtime"
I have tried the following.
Setting Applications Settings in the Azure Portal. These are supposed to get passed to the running Docker image as per the documentation but process.env.VariableName in my Node application is not set.
I have tried using a Docker compose file that sets the environment variables but again process.env.VariableName is empty.
I have even updated the VSTS build arguments passing the Variable to my Docker file on build which in turn sets the environment variable. Again no variable passed to the running Docker image.
My conclusion is that custom environment variables are not allowed in Azure Web App for Containers?
Am I doing something wrong?
As per the documentation the app settings are injected into the process as environment variables, however the environment variable name is prefixed with APPSETTING_, so in your Node application you would need to access the app setting with process.env.APPSETTING_VariableName.

azure WEBSITE_NAME appsetting is missing

Reading through the azure documentation and various posts on here, i understand there should be a number of settings available to web apps running on azure, among them WEBSITE_HOSTNAMEand WEBSITE_SITE_NAME. These should also overwrite any existing configuration appsettings with same key.
When i attempt to run my app, it is reading the key from the config file (i.e. its not being overwritten by azure). If i remove the value from the config, i get an exception about not being able to pick up a config value.
Is there a step im missing? Are these values only available at certain tiers?
Those values are only available as environment variables, so you'll need to read them from there.
App settings set in the Web App blade override settings and become env variables, but these are just environment variables.

Change EnvironmentName in IIS (vNext MVC6)

I try to use MVC6 and I want to use new feature "Changing configs by environment" in my apps
So as far as I understand I can choose proper config by changing environment variable ASPNET_ENV. I know two ways to change value of this variable
1) I change variable at Debug tab at Project Properties
2) I change variable at Azure Portal for my Azure Web Site
But how can I specify this variable in IIS after publishing website?
You can set specific user for the AppPool of your website, and then set environment variable for the user.

Resources