Search code examples
azuresystem-variable

setting the webapp %PATH% environment variable in azure


I am working on an azure webapp project. In order for my application to work, I needed to install a third party open source software on the server. The only way that I found to do that on the azure webapp, was to manually copy all the folders of the software on my project and then add all the required environment variables and also add few paths to the path system variable. I found how I can add the system variables, but I could not find the way to set the path variable on azure webapp.


Solution

  • You can achieve that through an XDT Transform (XML Document Transform).

    Check out https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples

    Adding environment variables

    The following will inject an environment variable named FOO, with value BAR, and add a folder to the PATH:

    <?xml version="1.0"?> 
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
      <system.webServer> 
        <runtime xdt:Transform="InsertIfMissing">
          <environmentVariables xdt:Transform="InsertIfMissing">
            <add name="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
            <add name="PATH" value="%PATH%;%HOME%\BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
          </environmentVariables>
        </runtime> 
      </system.webServer> 
    </configuration>
    

    Drop it in as d:\home\site\applicationHost.xdt, restart the Web App and check the freshly amended %PATH% in Kudu (https://sitename.scm.azurewebsites.net/DebugConsole).

    d:\home>set PATH
    Path=D:\home\site\deployments\tools;[...];D:\home\BAR