netlify / cli

Netlify Command Line Interface
http://cli.netlify.com
MIT License
1.57k stars 350 forks source link

Netlify env branch/context needs to be case sensitive #6494

Open zbobbert opened 6 months ago

zbobbert commented 6 months ago

Describe the bug

When setting (or unsetting) Netlify branch environment variables using the CLI, the --context parameter seems to be converted to lowercase, resulting in the environment variables being associated with the wrong branch name.

Steps to reproduce

Run netlify env:set test_env_var test_value --context "Case-Sensitive" I expect the resulting variable to be created under the "Case-Sensitive" branch, but instead it is created under the "case-sensitive" branch.

Configuration

[build] command = "npm run build" publish = ".next"

[[plugins]] package = "netlify-plugin-cypress"

Environment

System: OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish) CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor Memory: 3.14 GB / 30.49 GB Container: Yes Shell: 5.8.1 - /usr/bin/zsh Binaries: Node: 20.11.1 - ~/.volta/tools/image/node/20.11.1/bin/node Yarn: 1.22.10 - ~/.volta/bin/yarn npm: 10.2.4 - ~/.volta/tools/image/node/20.11.1/bin/npm

netlify --version netlify-cli/17.21.1 linux-x64 node-v20.11.1

zbobbert commented 6 months ago

Here's my workaround using the Netlify API:


SET_ENV_DATA=$(jq -n \
  --arg account_id "$NETLIFY_ACCOUNT_ID" \
  --arg site_id "$NETLIFY_SITE_ID" \
  --arg context_parameter "$BRANCH_NAME" \
  --arg key "test_env_var" \
  --arg value "test_value" \
  '{ $account_id, $key, $site_id, body: { context: "branch", $context_parameter, $value } }')
UPDATED_ENV_DATA=$(netlify api setEnvVarValue --data "${SET_ENV_DATA}")```