Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

azd env vars not passed to non-Docker build subprocesses (npm, dotnet, maven, swa, python) #6903

Closed
Closed
azd env vars not passed to non-Docker build subprocesses (npm, dotnet, maven, swa, python)#6903
Assignees

Description

Summary

When azd build (or azd package/azd deploy) runs non-Docker framework services, azd environment variables (from .azure//.env) 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//.env 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.go
  • cli/azd/pkg/tools/dotnet/dotnet.go
  • cli/azd/pkg/tools/maven/maven.go
  • cli/azd/pkg/tools/swa/swa.go

Framework services

  • cli/azd/pkg/project/framework_service_node.go
  • cli/azd/pkg/project/framework_service_dotnet.go
  • cli/azd/pkg/project/framework_service_maven.go
  • cli/azd/pkg/project/framework_service_swa.go
  • cli/azd/pkg/project/framework_service_python.go

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions