Describe the bug
When using a specific branch context for running netlify build or netlify deploy, no environment variables are being injected. This is because the API call for getting the correct branch specific environment variables is failing. The context that's provided, isn't allowed as the API returns the following error message:
{
"code": 400,
"message": "invalid request: non-compatible context"
}
Steps to reproduce
- Create a new Netlify site
- Add a environment variable (i.e.
FOO=BAR)
- Add a new branch, like
test and use a unique value for the environment variable (i.e. FOO=HELLO)
- Add a
console.log within your application so that the environment variable is visible when running netlify build (i.e. console.log(process.env.FOO))
- Run
netlify build for the specific branch (i.e. netlify build --context="branch:test)
- See that the log shows
undefined
- Run
netlify build for the generic branch-deploy context: netlify build --context="branch-deploy
- See that the logs are showing the correct environment variable
CLI command and flags
netlify build --context="branch:test"
Configuration
[build]
command = "pnpm build"
publish = ".next"
[dev]
command = "pnpm dev"
port = 8888
targetPort = 3000
autoLaunch = false
CLI output
Netlify Build
────────────────────────────────────────────────────────────────
❯ Version
@netlify/build 35.5.10
❯ Flags
accountId: [REDACTED]
deployId: [REDACTED]
packagePath: [REDACTED]
❯ Current directory
[REDACTED]
❯ Config file
[REDACTED]/netlify.toml
❯ Context
branch:test
❯ Using Next.js Runtime - v5.15.5
❯ Loading plugins
- [REDACTED] from netlify.toml and package.json
- [REDACTED] from netlify.toml and package.json
Plugin "[REDACTED]" internal error
─────────────────────────────────────────────────────────────────────
Error message
Could not import plugin:
ZodError: [
{
"expected": "string",
"code": "invalid_type",
"path": [
"[REDACTED]"
],
"message": "Invalid input: expected string, received undefined"
},
{
"expected": "number",
"code": "invalid_type",
"received": "NaN",
"path": [
"[REDACTED]"
],
"message": "[REDACTED] is required"
}
]
Plugin details
Package: [REDACTED]
npm link: [REDACTED]
Environment
System:
OS: macOS 15.7.3
CPU: (12) arm64 Apple M4 Pro
Memory: 74.17 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.21.1 - /Users/pvanmeijgaard/.local/state/fnm_multishells/76682_1769157887853/bin/node
npm: 10.9.4 - /Users/pvanmeijgaard/.local/state/fnm_multishells/76682_1769157887853/bin/npm
pnpm: 10.22.0 - /Users/pvanmeijgaard/.local/state/fnm_multishells/76682_1769157887853/bin/pnpm
bun: 1.3.6 - /opt/homebrew/bin/bun
Describe the bug
When using a specific branch context for running
netlify buildornetlify deploy, no environment variables are being injected. This is because the API call for getting the correct branch specific environment variables is failing. The context that's provided, isn't allowed as the API returns the following error message:Steps to reproduce
FOO=BAR)testand use a unique value for the environment variable (i.e.FOO=HELLO)console.logwithin your application so that the environment variable is visible when runningnetlify build(i.e.console.log(process.env.FOO))netlify buildfor the specific branch (i.e.netlify build --context="branch:test)undefinednetlify buildfor the genericbranch-deploycontext:netlify build --context="branch-deployCLI command and flags
netlify build --context="branch:test"Configuration
CLI output
Environment