mcloud-environments
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud CLI: Environments Commands
Cloud CLI:环境管理命令
Execute commands to manage environment lifecycle and deployments.
mcloud environments执行命令来管理环境生命周期与部署任务。
mcloud environmentsConstraints
约束条件
- Production environments cannot be deleted. Always check via
typebefore attempting delete in automation.environments get --json - Use for destructive operations (
--yes) in non-interactive contexts.delete - vs
redeployare not interchangeable — choose the right one based on where the fix is.trigger-build
- 生产环境无法删除。 在自动化执行删除操作前,务必通过命令检查环境的
environments get --json字段。type - 在非交互式场景下,执行破坏性操作(如)时需添加
delete参数。--yes - 与
redeploy不可互换使用,请根据问题修复的位置选择合适的命令。trigger-build
Commands
命令列表
environments list
environments list
List all environments in a project.
bash
mcloud environments list --organization <org-id> --project <project-id-or-handle> --jsonOptions:
- — Organization ID (falls back to active context)
-o/--organization <id> - — Project ID or handle (falls back to active context)
-p/--project <id-or-handle> - — Output as JSON
--json
列出项目中的所有环境。
bash
mcloud environments list --organization <org-id> --project <project-id-or-handle> --json可选参数:
- — 组织ID(若未指定则使用当前活跃上下文)
-o/--organization <id> - — 项目ID或别名(若未指定则使用当前活跃上下文)
-p/--project <id-or-handle> - — 以JSON格式输出结果
--json
environments get
environments get
Retrieve a single environment by handle.
bash
mcloud environments get <environment-handle> --organization <org-id> --project <project-id-or-handle> --jsonArguments:
- — Environment handle (required)
environment
Options:
- ,
-o/--organization <id>,-p/--project <id-or-handle>--json
通过环境别名获取单个环境的详细信息。
bash
mcloud environments get <environment-handle> --organization <org-id> --project <project-id-or-handle> --json必填参数:
- — 环境别名(必填)
environment
可选参数:
- 、
-o/--organization <id>、-p/--project <id-or-handle>--json
environments create
environments create
Create a new long-lived environment.
bash
mcloud environments create \
--organization <org-id> \
--project <project-id-or-handle> \
--name "Staging" \
--branch develop \
--jsonOptions:
- ,
-o/--organization <id>-p/--project <id-or-handle> - — Environment name (required)
-n/--name <name> - — Git branch to track (required)
-b/--branch <branch> - — Optional custom subdomain
--custom-subdomain <subdomain> - — Output as JSON
--json
创建一个长期运行的环境。
bash
mcloud environments create \
--organization <org-id> \
--project <project-id-or-handle> \
--name "Staging" \
--branch develop \
--json可选参数:
- 、
-o/--organization <id>-p/--project <id-or-handle> - — 环境名称(必填)
-n/--name <name> - — 要跟踪的Git分支(必填)
-b/--branch <branch> - — 可选的自定义子域名
--custom-subdomain <subdomain> - — 以JSON格式输出结果
--json
environments delete
environments delete
Delete an environment. Cannot delete production environments.
bash
mcloud environments delete <environment-handle> \
--organization <org-id> \
--project <project-id-or-handle> \
--yesArguments:
- — Environment handle (required)
environment
Options:
- ,
-o/--organization <id>-p/--project <id-or-handle> - — Skip confirmation prompt (required in non-interactive mode)
-y/--yes - — Output as JSON
--json
删除环境。生产环境无法删除。
bash
mcloud environments delete <environment-handle> \
--organization <org-id> \
--project <project-id-or-handle> \
--yes必填参数:
- — 环境别名(必填)
environment
可选参数:
- 、
-o/--organization <id>-p/--project <id-or-handle> - — 跳过确认提示(非交互式模式下必填)
-y/--yes - — 以JSON格式输出结果
--json
environments redeploy
environments redeploy
Re-run an existing build for the active deployment. Use when the fix is environment-side (variable change, infra issue) — does NOT start a new build.
bash
mcloud environments redeploy <environment-handle> \
--organization <org-id> \
--project <project-id-or-handle> \
--jsonArguments:
- — Environment handle (required)
environment
Options:
- ,
-o/--organization <id>,-p/--project <id-or-handle>--json
Requires the environment to have an active deployment. If it doesn't, usefirst.trigger-build
为当前部署重新执行已有的构建任务。适用于修复环境端问题(如变量变更、基础设施问题)的场景——不会启动新的构建任务。
bash
mcloud environments redeploy <environment-handle> \
--organization <org-id> \
--project <project-id-or-handle> \
--json必填参数:
- — 环境别名(必填)
environment
可选参数:
- 、
-o/--organization <id>、-p/--project <id-or-handle>--json
要求环境存在活跃部署。若没有活跃部署,请先使用命令。trigger-build
environments trigger-build
environments trigger-build
Start a new build from the tracked branch. Use when the fix is committed code — creates a new deployment.
bash
mcloud environments trigger-build <environment-handle> \
--organization <org-id> \
--project <project-id-or-handle> \
--jsonArguments:
- — Environment handle (required)
environment
Options:
- ,
-o/--organization <id>,-p/--project <id-or-handle>--json
从跟踪的分支启动新的构建任务。适用于修复源代码问题的场景——会创建新的部署。
bash
mcloud environments trigger-build <environment-handle> \
--organization <org-id> \
--project <project-id-or-handle> \
--json必填参数:
- — 环境别名(必填)
environment
可选参数:
- 、
-o/--organization <id>、-p/--project <id-or-handle>--json
Redeploy vs Trigger-Build Decision
Redeploy与Trigger-Build选择指南
| Command | When to use |
|---|---|
| Fix is environment-side (variable change, infra config) — reruns existing build |
| Fix is in source code on the tracked branch — starts a new build |
| 命令 | 使用场景 |
|---|---|
| 修复环境端问题(变量变更、基础设施配置)——重新执行已有构建 |
| 修复跟踪分支上的源代码问题——启动新构建 |
Examples
示例
bash
undefinedbash
undefinedList all environments
列出所有环境
mcloud environments list --json
mcloud environments list --json
Get environment details and check type before deleting
获取环境详情并在删除前检查类型
mcloud environments get staging --json | jq '{id, name, type, status}'
mcloud environments get staging --json | jq '{id, name, type, status}'
Create a new environment tracking the develop branch
创建一个跟踪develop分支的新环境
mcloud environments create --name "Staging" --branch develop --json
mcloud environments create --name "Staging" --branch develop --json
Delete a non-production environment
删除非生产环境
mcloud environments delete staging --yes
mcloud environments delete staging --yes
Redeploy after a variable change
变量变更后重新部署
mcloud environments redeploy production --json
mcloud environments redeploy production --json
Trigger a fresh build from source
从源代码触发新构建
mcloud environments trigger-build production --json
mcloud environments trigger-build production --json
Find environment handles by name
通过环境名称查找环境别名
mcloud environments list --json
| jq -r '.[] | select(.name == "Production") | .handle'
| jq -r '.[] | select(.name == "Production") | .handle'
mcloud environments list --json
| jq -r '.[] | select(.name == "Production") | .handle'
| jq -r '.[] | select(.name == "Production") | .handle'
Verify new build started
验证新构建已启动
mcloud deployments list --environment production --limit 5 --json
| jq '.[] | {id, backend_status, updated_at}'
| jq '.[] | {id, backend_status, updated_at}'
undefinedmcloud deployments list --environment production --limit 5 --json
| jq '.[] | {id, backend_status, updated_at}'
| jq '.[] | {id, backend_status, updated_at}'
undefined