zeabur-variables

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Zeabur Variables Management

Zeabur 变量管理

Always use
npx zeabur@latest
to invoke Zeabur CLI.
Never use
zeabur
directly or any other installation method. If
npx
is not available, install Node.js first.
Do not guess CLI syntax. Only
create
,
update
,
delete
,
env
, and
list
are valid subcommands. Subcommands like
set
or
add
do not exist and will silently fail with no error output.
请始终使用
npx zeabur@latest
调用Zeabur CLI。
切勿直接使用
zeabur
或其他任何安装方式。如果没有
npx
,请先安装Node.js。
不要猜测CLI语法。 只有
create
update
delete
env
list
是有效的子命令。
set
add
这类子命令不存在,会无错误输出地静默失败。

Known Issues

已知问题

  1. Use
    --id
    not
    --name
    — name lookup is unreliable
  2. ${VAR}
    gets empty
    — shell expands before CLI receives; use single quotes
  3. variable env
    replaces ALL variables
    — it overwrites the entire variable set with the .env file contents; existing variables not in the file will be removed
  1. 使用
    --id
    而非
    --name
    —— 通过名称查找不可靠
  2. ${VAR}
    变为空值
    —— 外壳会在CLI接收前展开变量;请使用单引号
  3. variable env
    会替换所有变量
    —— 它会用.env文件的内容覆盖整个变量集合;文件中不存在的现有变量将被删除

Create Variables

创建变量

Creates new variables. Errors if a key already exists — use
update
to change existing keys.
bash
undefined
创建新变量。如果键已存在则报错 —— 请使用
update
修改现有键。
bash
undefined

Always use service ID — use the
zeabur-service-list
skill to get it

请始终使用服务ID —— 使用
zeabur-service-list
技能获取

npx zeabur@latest variable create --id <service-id>
-k "KEY1=value1"
-k "KEY2=value2"
-y -i=false
undefined
npx zeabur@latest variable create --id <service-id>
-k "KEY1=value1"
-k "KEY2=value2"
-y -i=false
undefined

Update Variables

更新变量

Updates only the specified keys. Does NOT clear other variables.
bash
npx zeabur@latest variable update --id <service-id> \
  -k "KEY1=new_value1" \
  -k "KEY2=new_value2" \
  -y -i=false
仅更新指定的键。不会清除其他变量。
bash
npx zeabur@latest variable update --id <service-id> \
  -k "KEY1=new_value1" \
  -k "KEY2=new_value2" \
  -y -i=false

Delete Variables

删除变量

Deletes only the specified keys.
bash
npx zeabur@latest variable delete --id <service-id> \
  --delete-keys "KEY1" \
  --delete-keys "KEY2" \
  -y -i=false
仅删除指定的键。
bash
npx zeabur@latest variable delete --id <service-id> \
  --delete-keys "KEY1" \
  --delete-keys "KEY2" \
  -y -i=false

List Variables

列出变量

bash
npx zeabur@latest variable list --id <service-id> -i=false
bash
npx zeabur@latest variable list --id <service-id> -i=false

Load from .env File

从.env文件加载

Warning: This replaces ALL variables on the service with the contents of the .env file. Existing variables not in the file will be removed.
bash
npx zeabur@latest variable env --id <service-id> -f .env
After running
env
, you must restart the service manually to apply changes.
警告: 此操作会用.env文件的内容替换服务上的所有变量。文件中不存在的现有变量将被删除。
bash
npx zeabur@latest variable env --id <service-id> -f .env
运行
env
命令后,必须手动重启服务才能使更改生效。

Variable References

变量引用

Warning: The CLI
-k
flag uses Cobra's
StringToStringVar
parser which cannot reliably handle values containing
${}
, even with single quotes. The value may be truncated or emptied. See zeabur/cli#201.
bash
undefined
警告: CLI的
-k
标志使用Cobra的
StringToStringVar
解析器,即使使用单引号,也无法可靠处理包含
${}
的值。值可能会被截断或清空。详情请见zeabur/cli#201
bash
undefined

WRONG — shell expands ${VAR} to empty

错误示例 —— 外壳会将${VAR}展开为空值

npx zeabur@latest variable create --id <service-id> -k "REDIS_URL=${REDIS_URI_INTERNAL}" -y -i=false
npx zeabur@latest variable create --id <service-id> -k "REDIS_URL=${REDIS_URI_INTERNAL}" -y -i=false

STILL UNRELIABLE — single quotes prevent shell expansion but Cobra's CSV parser may still mangle the value

仍不可靠 —— 单引号可防止外壳展开,但Cobra的CSV解析器仍可能损坏值

npx zeabur@latest variable create --id <service-id> -k 'REDIS_URL=${REDIS_URI_INTERNAL}' -y -i=false
npx zeabur@latest variable create --id <service-id> -k 'REDIS_URL=${REDIS_URI_INTERNAL}' -y -i=false

RECOMMENDED — set variable references in Zeabur Dashboard

推荐方式 —— 在Zeabur控制台中设置变量引用

Or use GraphQL API with updateEnvironmentVariable(data: Map!) mutation

或使用带有updateEnvironmentVariable(data: Map!) mutation的GraphQL API


For cross-service variable references like `${POSTGRES_CONNECTION_STRING}` (Zeabur uses a flat namespace — all exposed variables from other services are merged directly, no service prefix needed), **always use the Zeabur Dashboard** until the CLI bug is fixed.

对于跨服务变量引用,例如`${POSTGRES_CONNECTION_STRING}`(Zeabur使用扁平命名空间——所有来自其他服务的暴露变量会直接合并,无需服务前缀),**请始终使用Zeabur控制台**,直到CLI的bug修复。

Quick Reference

快速参考

NeedCommandBehavior
Add new vars
npx zeabur@latest variable create --id <service-id> -k "K=V" -y -i=false
Errors if key exists
Change existing vars
npx zeabur@latest variable update --id <service-id> -k "K=V" -y -i=false
Only updates specified keys
Remove specific vars
npx zeabur@latest variable delete --id <service-id> --delete-keys "K" -y -i=false
Only removes specified keys
Overwrite all vars from file
npx zeabur@latest variable env --id <service-id> -f .env
Replaces entire variable set
View vars
npx zeabur@latest variable list --id <service-id> -i=false
Read-only
需求命令行为
添加新变量
npx zeabur@latest variable create --id <service-id> -k "K=V" -y -i=false
若键已存在则报错
修改现有变量
npx zeabur@latest variable update --id <service-id> -k "K=V" -y -i=false
仅更新指定的键
删除特定变量
npx zeabur@latest variable delete --id <service-id> --delete-keys "K" -y -i=false
仅删除指定的键
从文件覆盖所有变量
npx zeabur@latest variable env --id <service-id> -f .env
替换整个变量集合
查看变量
npx zeabur@latest variable list --id <service-id> -i=false
只读