You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -17,14 +17,11 @@ The Azure Developer CLI (`azd`) uses environment variables to store and manage c
17
17
18
18
In the context of the Azure Developer CLI, environment variables are key-value pairs that are tied to specific named environments like *dev*, *test*, or *prod*. Each `azd` environment maintains its own set of environment variables, allowing you to configure different settings for different deployment targets.
19
19
20
-
### What are environment variables
20
+
Environment variables in `azd`are configuration settings stored in `.env` files within your environment folders in the `.azure` folder. They serve as inputs to:
21
21
22
-
Environment variables in `azd` are configuration settings stored in `.env` files within your environment folders. They serve as inputs to:
23
-
24
-
- Infrastructure provisioning processes
25
22
- Application deployment workflows
26
-
-Runtime configurations for Azure services
27
-
-Feature flags and connection parameters
23
+
-Configurations for Azure services and connections
24
+
-Infrastructure provisioning processes
28
25
29
26
Unlike traditional environment variables that exist at the operating system level, `azd` environment variables are scoped to specific environments within your project, providing isolation between different deployment targets.
30
27
@@ -42,105 +39,40 @@ Each `azd` environment has its own set of variables, allowing for environment-sp
42
39
43
40
The `azd` environment variables are stored in `.env` files within the environment-specific directories of your project. When you create an environment using `azd env new <name>`, a directory structure is created:
44
41
45
-
```text
42
+
```txt
46
43
.azure/
47
44
├── <environment-name>/
48
45
│ ├── .env # Environment variables for this environment
The `.env` file uses a standard format where each line represents a key-value pair:
53
49
54
-
```text
50
+
```txt
55
51
KEY1=value1
56
52
KEY2=value2
57
53
```
58
54
59
55
> [!TIP]
60
56
> Visit the [Working with environments](work-with-environments.md) article for more information about `azd` environments.
61
57
62
-
When you run `azd` commands targeting a specific environment, the CLI automatically loads variables from that environment's `.env` file.
58
+
When you run `azd` commands such as `azd up`, the CLI automatically loads variables from the select environment's `.env` file.
63
59
64
60
These variables influence:
65
61
66
62
-**Infrastructure provisioning**: Variables like `AZURE_LOCATION` and `AZURE_SUBSCRIPTION_ID` determine where and how resources are created.
67
-
-**Deployment**: Variables like service endpoints and connection strings control how your application connects to Azure services.
68
-
-**Application configuration**: Variables can be passed to your application to control its behavior.
69
-
-**Resource naming**: Variables like `RESOURCE_TOKEN` ensure consistent resource naming patterns.
70
-
71
-
The `.env` file is also updated automatically during operations like `azd init`, `azd provision`, and `azd deploy`, capturing outputs from your infrastructure templates and storing them for future use.
72
-
73
-
## AZD vs OS environment variables
74
-
75
-
`azd` environment variables and operating system environment variables serve different purposes and work in different ways:
76
-
77
-
| Concept | Azure Developer CLI | Operating system |
**Convert azd environment variables to OS environment variables:**
111
-
112
-
**Bash:**
113
-
114
-
```bash
115
-
# Load all azd environment variables into the current shell session
116
-
while IFS='='read -r key value;do
117
-
value=$(echo "$value"| sed 's/^"//'| sed 's/"$//')
118
-
export"$key=$value"
119
-
done<<EOF
120
-
$(azd env get-values)
121
-
EOF
122
-
```
123
-
124
-
**PowerShell:**
125
-
126
-
```powershell
127
-
# Load all azd environment variables into the current PowerShell session
128
-
foreach ($line in (& azd env get-values)) {
129
-
if ($line -match "([^=]+)=(.*)") {
130
-
$key = $matches[1]
131
-
$value = $matches[2] -replace '^"|"$'
132
-
$env:$key = $value
133
-
}
134
-
}
135
-
```
67
+
The `.env` file is also updated automatically by `azd` during operations like `azd init`, `azd provision`, and `azd deploy`, capturing outputs from your infrastructure templates and storing them for future use.
136
68
137
69
## Set Environment Variables
138
70
139
71
You can use different methods to set `azd` environment variables, depending on the scenario.
140
72
141
73
### CLI commands
142
74
143
-
The most direct way to set an environment variable is using the `azd env set` command:
75
+
The recommended way to set an environment variable is using the `azd env set` command, which includes checks to ensure valid values:
144
76
145
77
```azdeveloper
146
78
azd env set <key> <value>
@@ -228,7 +160,7 @@ For machine-readable output (useful in scripts):
228
160
azd env get-values --output json
229
161
```
230
162
231
-
### Bicep files
163
+
### Pass environment variables to Bicep files
232
164
233
165
Environment variables can be referenced in Bicep parameter files (`main.parameters.json`) using a special substitution syntax:
234
166
@@ -253,7 +185,7 @@ When `azd` processes this file during provisioning, it automatically substitutes
253
185
254
186
In custom scripts and [hooks](azd-extensibility.md) defined in your `azure.yaml` file, you can access environment variables using the `azd env get-values` command:
255
187
256
-
**Bash:**
188
+
### [Bash](#tab/bash)
257
189
258
190
```bash
259
191
#!/bin/bash
@@ -270,7 +202,7 @@ EOF
270
202
echo"API endpoint: $API_ENDPOINT"
271
203
```
272
204
273
-
**PowerShell:**
205
+
### [PowerShell](#tab/powershell)
274
206
275
207
```powershell
276
208
Write-Host "Loading azd .env file from current environment"
0 commit comments