Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Azure: how do I expose a configuration setting as an environment variable?

I tried adding this to my ServiceDefinition.csdef file:

<WorkerRole ...><Runtime><Environment>
    <Variable name="AZURE_STORAGE_ACCOUNT">
      <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='AZURE_STORAGE_ACCOUNT']/@value" />
    </Variable>
</Environment></Runtime></WorkerRole>

And I set the configuration setting in my ServiceConfiguration.Cloud.cscfg file:

<Role name="WorkerRole">
  <ConfigurationSettings>
    <Setting name="AZURE_STORAGE_ACCOUNT" value="<secret stuff>" />
  </ConfigurationSettings>
</Role>

But I got the following error when I run cspack:

CloudServices091 : The '/RoleEnvironment/CurrentInstance/Configur
ationSettings/ConfigurationSetting[@name='AZURE_STORAGE_ACCOUNT']/@value' is an
invalid xpath expression.
like image 864
Andres Riofrio Avatar asked May 03 '12 06:05

Andres Riofrio


People also ask

How do I set an environment variable in Azure?

To set environment variables when you start a container in the Azure portal, specify them in the Advanced page when you create the container. Under Environment variables, enter NumWords with a value of 5 for the first variable, and enter MinLength with a value of 8 for the second variable.

How do I get the Azure app configuration value?

You can use the Azure portal or the Azure CLI to retrieve past key-values. Sign in to the Azure portal. Select All resources, and select the App Configuration store instance where your key-value are stored. In the Operations menu, select Restore.

How do I read Azure function configuration?

Recommended way — use environment variable to read settings. var value = Environment. GetEnvironmentVariable("your_key_here"); The System.


1 Answers

Are you missing the declaration of that setting? I don't see the appropriate element in your .csdef, something like <ConfigurationSettings><Setting name="AZURE_STORAGE_ACCOUNT"/></ConfigurationSettings>. You need one of those in your .csdef, and then you still want the one in your .cscfg that includes the value.

If you're using Visual Studio, it should edit both files for you if you use its property view. (Just double click the role and then click around to get to config settings and add a new one.)

like image 75
user94559 Avatar answered Oct 05 '22 09:10

user94559