How to pass environment variables in Azure WebApps
akhilsharmaazure

How to pass environment variables in Azure WebApps


I came across this topic in one of Microsoft Azure Community Tech Support questions. The person tried passing and updating the environment variables through one of his configuration files, yet the environment variables were not getting updated/changed.

In this post, we’ll be covering one of the most simplest ways of passing environment variables in an Azure Webapp.

If you don’t know what is Azure WebApp? It is a managed PaaS service that helps to develop and deploy enterprise-ready web applications. It provides powerful capabilities such as built-in development operations, continuous integration with Visual Studio Online and GitHub, staging and production support, and automatic patching for Azure developers to quick create web applications. It also enables integration with on-premises or other cloud systems.

How do we pass environment variables?

In order to pass the environment variables, please follow the below steps:

  • Navigate to the Azure WebApp in which you wish to pass the custom variable.
  • In the WebApp’s left menu, navigate to Configuration and click on it.
  • Configuration should open upon clicking on the Configuration setting.
  • Click on the Application Setting tab if not already selected.
  • Click on “New Application Setting”.

  • Enter the name and value of the variable you wish to pass in the WebApp’s environment.
  • Select the “deployment slot setting” option if the variable’s scope is limited to the deployment slot.
  • Click on Save Button.
  • Your value should appear in the list of application settings shown in the list of already configured settings.

There you are, you have successfully set the environment variable for the Azure WebApp.

Validation of Environment Variable

In order to validate the environment variable in your Azure WebApp, please follow the following steps:

  • Navigate and click on the Advanced Tools in WebApp’s left menu.
  • Click on GO

  • A Kudu console should open in a separate tab corresponding to your webapp.
  • Click on Environment Button on the top menu of Kudu console.

  • You should be able to view the complete list of AppSettings, System variables, Environment variables etc on your screen.
  • Search for your environment variable.
  • You should be able to see two entries added for your variable in the Environment Variables.
    • APPSETTING_YourVariable=YourValue
    • YourVariable=YourValue

Reference

https://docs.microsoft.com/en-us/azure/app-service/configure-common