Pingpong
Pingpong

Reputation: 8009

AzureWebJobsScriptRoot variable is not defined on Azure Functions, but returns correct value locally

AzureWebJobsScriptRoot variable is not defined on Azure Functions. The code below returns no value. System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)["AzureWebJobsScriptRoot"];

However, %HOME%\site\wwwroot will be returned based on below:

AzureWebJobsScriptRoot

AzureWebJobsScriptRoot

The path to the root directory where the host.json file and function folders are located. In a function app, the default is %HOME%\site\wwwroot.

Key Sample value

AzureWebJobsScriptRoot %HOME%\site\wwwroot

It returns correct value locally, not %HOME%\site\wwwroot

Update

Is this a bug with Azure Functions?

If so, what is an alternative solution?

Before the issue is fixed by Microsoft, can this variable, AzureWebJobsScriptRoot, be defined myself to "%HOME%\site\wwwroot" on Azure?

https://github.com/Azure/Azure-Functions/issues/1146 https://github.com/MicrosoftDocs/azure-docs/issues/26761

Upvotes: 1

Views: 2323

Answers (2)

Ketan
Ketan

Reputation: 1550

If you configure a function app with a different value for AzureWebJobsScriptRoot, then the functions host should honor that new value. For example, if you set AzureWebJobsScriptRoot = D:\home\site\wwwroot\foo then the functions host would look for a host.json file and function directories in the D:\home\site\wwwroot\foo location.

By default, this environment variable is not set. So it is expected that if you did not set it yourself, then System.Environment.GetEnvironmentVariable("AzureWebJobsScriptRoot") will return null.

Be aware that if you modify this setting, other components like the portal, visual studio, visual studio code, etc will not be aware of setting and will deploy your code to the normal default location. If you want to customize this setting, its up to you to make sure the application code is deployed to the right location.

Please refer the full details here

Upvotes: 0

Joey Cai
Joey Cai

Reputation: 20067

I test in my site and get the same problem with you. As the article said, when running in Azure, will default to %HOME%\site\wwwroot and it set the function folder under home\site\wwwroot.

However, when I set AzureWebJobsScriptRoot in Azure funtion Application Settings, it will show in the output like below:

enter image description here enter image description here

Upvotes: 0

Related Questions