mcloud-environments

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloud CLI: Environments Commands

Cloud CLI:环境管理命令

Execute
mcloud environments
commands to manage environment lifecycle and deployments.
执行
mcloud environments
命令来管理环境生命周期与部署任务。

Constraints

约束条件

  • Production environments cannot be deleted. Always check
    type
    via
    environments get --json
    before attempting delete in automation.
  • Use
    --yes
    for destructive operations (
    delete
    ) in non-interactive contexts.
  • redeploy
    vs
    trigger-build
    are not interchangeable — choose the right one based on where the fix is.
  • 生产环境无法删除。 在自动化执行删除操作前,务必通过
    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> --json
Options:
  • -o/--organization <id>
    — Organization ID (falls back to active context)
  • -p/--project <id-or-handle>
    — Project ID or handle (falls back to active context)
  • --json
    — Output as JSON
列出项目中的所有环境。
bash
mcloud environments list --organization <org-id> --project <project-id-or-handle> --json
可选参数:
  • -o/--organization <id>
    — 组织ID(若未指定则使用当前活跃上下文)
  • -p/--project <id-or-handle>
    — 项目ID或别名(若未指定则使用当前活跃上下文)
  • --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> --json
Arguments:
  • environment
    — Environment handle (required)
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 \
  --json
Options:
  • -o/--organization <id>
    ,
    -p/--project <id-or-handle>
  • -n/--name <name>
    — Environment name (required)
  • -b/--branch <branch>
    — Git branch to track (required)
  • --custom-subdomain <subdomain>
    — Optional custom subdomain
  • --json
    — Output as 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>
    — 环境名称(必填)
  • -b/--branch <branch>
    — 要跟踪的Git分支(必填)
  • --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> \
  --yes
Arguments:
  • environment
    — Environment handle (required)
Options:
  • -o/--organization <id>
    ,
    -p/--project <id-or-handle>
  • -y/--yes
    — Skip confirmation prompt (required in non-interactive mode)
  • --json
    — Output as 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> \
  --json
Arguments:
  • environment
    — Environment handle (required)
Options:
  • -o/--organization <id>
    ,
    -p/--project <id-or-handle>
    ,
    --json
Requires the environment to have an active deployment. If it doesn't, use
trigger-build
first.
为当前部署重新执行已有的构建任务。适用于修复环境端问题(如变量变更、基础设施问题)的场景——不会启动新的构建任务。
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> \
  --json
Arguments:
  • environment
    — Environment handle (required)
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选择指南

CommandWhen to use
redeploy
Fix is environment-side (variable change, infra config) — reruns existing build
trigger-build
Fix is in source code on the tracked branch — starts a new build
命令使用场景
redeploy
修复环境端问题(变量变更、基础设施配置)——重新执行已有构建
trigger-build
修复跟踪分支上的源代码问题——启动新构建

Examples

示例

bash
undefined
bash
undefined

List 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'
mcloud environments list --json
| jq -r '.[] | select(.name == "Production") | .handle'

Verify new build started

验证新构建已启动

mcloud deployments list --environment production --limit 5 --json
| jq '.[] | {id, backend_status, updated_at}'
undefined
mcloud deployments list --environment production --limit 5 --json
| jq '.[] | {id, backend_status, updated_at}'
undefined