Skip to content

Commit dc047ef

Browse files
committed
Environment Variable usage and lifetimes
1 parent f82c287 commit dc047ef

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Environment Variable Lifetimes
2+
3+
# 1. Session ($env:VARIABLE)
4+
$env:MY_VAR = "value1"
5+
Write-Host $env:MY_VAR
6+
7+
# 1.1. Environment variable with dynamic key
8+
$key = "MY_VAR"
9+
Set-Item "env:$key" "value2"
10+
11+
# 2. Process-Level Inheritance
12+
# when you set an environment variable in PowerShell,
13+
# it is inherited by child processes (like dotnet run, git, or other spawned applications).
14+
15+
# 3. Permanent Environment Variables (Registry)
16+
[System.Environment]::SetEnvironmentVariable("MY_VAR", "value1", "User")
17+
Write-Host $env:MY_VAR
18+
19+
# 4. Environment Variables in GitHubs Actions
20+
# Environment variables set during one step are not automatically available in subsequent steps in GitHub Actions.
21+
# To persist environment variables between steps, you need to explicitly use the GITHUB_ENV file.
22+
$value = "value1"
23+
echo "$key=$value" >> $env:GITHUB_ENV

0 commit comments

Comments
 (0)