feat: pass azd environment variables to all framework service subprocesses#6905
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enables azd environment variables (from .azure/<env>/.env) to be passed to all non-Docker framework service build subprocesses (npm/pnpm/yarn, dotnet, maven, swa, python). Previously, only Docker builds and hooks received these variables, preventing frontend frameworks like Vite and Next.js from accessing build-time environment variables.
Changes:
- Added
env []stringparameter to CLI tool wrapper methods across all non-Docker build tools - Updated framework services to pass
env.Environ()at each call site during build/restore/package operations - Updated all tests to pass
nilfor backward compatibility - Included unrelated race condition fix in progress_log.go
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pkg/tools/node/node.go |
Added env parameter to Install/RunScript/Prune for all package managers (npm/pnpm/yarn) |
pkg/tools/node/detect.go |
Package manager detection logic (from PR #6894) |
pkg/tools/node/detect_test.go |
Tests for package manager detection (from PR #6894) |
pkg/tools/node/node_test.go |
CLI tests updated with nil env parameter |
pkg/tools/dotnet/dotnet.go |
Added env parameter to Restore/Build/Publish, correctly appends to existing env vars |
pkg/tools/maven/maven.go |
Added env parameter to Compile/Package/ResolveDependencies |
pkg/tools/swa/swa.go |
Added env parameter to Build/Deploy methods |
pkg/tools/python/python.go |
Added env parameter to CreateVirtualEnv/InstallRequirements/InstallProject/Run |
pkg/tools/swa/swa_test.go |
Updated test calls to include nil env parameter |
pkg/tools/python/python_test.go |
Updated test calls to include nil env parameter |
pkg/project/framework_service_node.go |
Passes env.Environ() to node CLI methods |
pkg/project/framework_service_dotnet.go |
Passes env.Environ() to dotnet CLI methods |
pkg/project/framework_service_maven.go |
Passes env.Environ() to maven CLI methods |
pkg/project/framework_service_swa.go |
Passes env.Environ() to swa CLI build |
pkg/project/framework_service_python.go |
Passes env.Environ() to python CLI methods |
pkg/project/service_target_staticwebapp.go |
Passes env.Environ() to swa CLI deploy |
pkg/project/framework_service_node_test.go |
Updated imports from npm to node, added PM config tests |
pkg/project/framework_service_docker_test.go |
Updated imports from npm to node |
pkg/ai/python_bridge.go |
Updated to pass nil (AI bridge doesn't need azd env) |
pkg/input/progress_log.go |
Fixed race conditions in Start/Stop/Header methods |
cmd/container.go |
Updated IoC registrations for node package rename |
.vscode/cspell.yaml |
Added yarnpkg to dictionary |
extensions/azure.ai.agents/internal/cmd/init_from_code_test.go |
Removed trailing newline |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a6953ee to
cf855f4
Compare
…esses Previously, azd environment variables from .azure/<env>/.env were only passed to Docker builds and hooks, but not to non-Docker framework service builds (npm/pnpm/yarn, dotnet, maven, swa, python). This meant frontend builds like Vite/React couldn't access env vars like VITE_API_URL during build time. Added env []string parameter to all CLI tool wrapper methods and updated framework services to pass env.Environ() at each call site: - node: Install(), RunScript(), Prune() for npm/pnpm/yarn - dotnet: Build(), Publish(), Restore() - maven: Compile(), Package(), ResolveDependencies() - swa: Build(), Deploy() - python: CreateVirtualEnv(), InstallRequirements(), InstallProject(), Run() Also fixed SWA Deploy not passing env vars to the swa CLI subprocess, and updated the static web app deploy target accordingly. Closes Azure#6903 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Break long line in framework_service_dotnet.go (127 > 125 char limit) - Break long line in node.go npmCli.Install (129 > 125 char limit) - Remove unused executeCommand() in swa.go (replaced by direct cli.run() call) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cf855f4 to
e1b3a42
Compare
Add tests verifying that environment variables are forwarded to subprocess RunArgs for node (Install, RunScript), python (InstallRequirements), and swa (Build) CLI wrappers. Add comments in dotnet.go explaining why env vars are appended (to preserve base env set by newDotNetRunArgs like DOTNET_NOLOGO). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Summary
Pass azd environment variables (from
.azure/<env>/.env) to all non-Docker framework service build subprocesses. Previously only Docker builds and hooks received these variables.Closes #6903
Depends on: #6894 (pnpm/yarn support — this PR builds on top of that branch)
Changes
Added
env []stringparameter to CLI tool wrapper methods and updated framework services to passenv.Environ()at each call site:CLI Tool Wrappers
pkg/tools/node/node.go)Install(),RunScript(),Prune()— all 3 implementations (npm, pnpm, yarn)pkg/tools/dotnet/dotnet.go)Build(),Publish(),Restore()pkg/tools/maven/maven.go)Compile(),Package(),ResolveDependencies()pkg/tools/swa/swa.go)Build(),Deploy()pkg/tools/python/python.go)CreateVirtualEnv(),InstallRequirements(),InstallProject(),Run()Framework Services
framework_service_node.goframework_service_dotnet.goframework_service_maven.goframework_service_swa.goframework_service_python.goDeploy Targets
service_target_staticwebapp.goOther
pkg/ai/python_bridge.go— Updated 3 callers to passnil(no azd env needed for AI bridge)Testing
go build ./...passesnilfor the new env parameter (backward compatible)Why this matters
Frontend frameworks like Vite, Next.js, and Create React App read environment variables at build time (e.g.,
VITE_API_URL,NEXT_PUBLIC_API_URL). Without this fix, users had to use pre-build hooks as a workaround to set env vars before builds.