-
Notifications
You must be signed in to change notification settings - Fork 272
Description
Summary
When azd build (or azd package/azd deploy) runs non-Docker framework services, azd environment variables (from .azure/) are not passed to the build subprocess. This means frontend builds (e.g., npm run build for Vite/React) cannot access env vars like VITE_API_URL stored in the azd environment.
What works
- Docker builds correctly pass azd env vars via
container_helper.go:427-430(env.Environ()-docker.Build(WithEnv(...))) - Hooks (pre/post scripts) correctly pass azd env vars via
hooks_runner.go:145-169
What doesn't work
The following framework services do NOT pass azd env vars to their build subprocesses:
| Component | CLI Method | Issue |
|---|---|---|
| Node (npm/pnpm/yarn) Build/Package/Restore | node.Cli.RunScript(), Install() |
No .WithEnv() on RunArgs |
| .NET Build/Restore/Publish | dotnet.Cli.Build(), Restore(), Publish() |
newDotNetRunArgs() has no env |
| Maven Build/Package/Restore | maven.Cli.Compile(), Package(), ResolveDependencies() |
No .WithEnv() |
| SWA Build | swa.Cli.Build() - run() |
No .WithEnv() |
| Python Restore | pip install via command runner |
No .WithEnv() |
Root Cause
The non-Docker framework services all have env *environment.Environment as a struct field (injected at construction time), but they never call env.Environ() to pass the azd environment variables to the CLI tool wrappers. The CLI tool wrappers create RunArgs without calling .WithEnv().
The appendEnv() function in command_runner.go returns nil when no env is provided, causing Go to inherit only the parent process env. But azd env vars from .azure/ are loaded in-memory and not part of the host process environment -- so they never reach the subprocess.
Proposed Fix
Add env []string parameter to each CLI tool wrapper method (Install, RunScript, Build, Compile, etc.) and call .WithEnv(env) on RunArgs. Framework services then pass self.env.Environ() at each call site.
This is consistent with how docker.Cli already passes build env vars.
Affected files
CLI tool wrappers
cli/azd/pkg/tools/node/node.gocli/azd/pkg/tools/dotnet/dotnet.gocli/azd/pkg/tools/maven/maven.gocli/azd/pkg/tools/swa/swa.go
Framework services
cli/azd/pkg/project/framework_service_node.gocli/azd/pkg/project/framework_service_dotnet.gocli/azd/pkg/project/framework_service_maven.gocli/azd/pkg/project/framework_service_swa.gocli/azd/pkg/project/framework_service_python.go