environments Command - Medusa Cloud CLI Reference

In this guide, you'll learn how to manage your Cloud environments using the CLI.

environments list#

List all environments in a project.

Options#

Option

Description

Required

Default

-o <id>, --organization <id>

The ID of the organization that the project belongs to.

Yes

Falls back to the organization in the active context, if set.

-p <id-or-handle>, --project <id-or-handle>

The ID or handle of the project to list environments from.

Yes

Falls back to the project in the active context, if set.

--json

Print the result as JSON instead of formatted text.

No

false


environments get#

Retrieve a single environment by its handle. This is useful if you want to retrieve the environment's details, such as its status or tracked branch.

Returns the following information:

Arguments#

Option

Description

Required

environment

The handle of the environment to retrieve.

Yes

Options#

Option

Description

Required

Default

-o <id>, --organization <id>

The ID of the organization that the environment belongs to.

Yes

Falls back to the organization in the active context, if set.

-p <id-or-handle>, --project <id-or-handle>

The ID or handle of the project that the environment belongs to.

Yes

Falls back to the project in the active context, if set.

--json

Print the result as JSON instead of formatted text.

No

false


environments create#

Create a new long-lived environment for a project. You must already have a branch in your repository to track. The environment will be deployed and updated with every push to the tracked branch.

Options#

Option

Description

Required

Default

-o <id>, --organization <id>

The ID of the organization to create the environment in.

Yes

Falls back to the organization in the active context, if set.

-p <id-or-handle>, --project <id-or-handle>

The ID or handle of the project to create the environment in.

Yes

Falls back to the project in the active context, if set.

-n <name>, --name <name>

Display name for the new environment.

Yes

-

-b <branch>, --branch <branch>

The Git branch this environment tracks. Pushes to this branch trigger new deployments.

Yes

-

--custom-subdomain <subdomain>

Custom subdomain for the environment's URL.

No

-

--json

Print the result as JSON instead of formatted text.

No

false


environments delete#

Delete an environment by its handle.

Warning: Deleting an environment is irreversible and removes all associated deployments and resources. Production environments cannot be deleted.

Arguments#

Option

Description

Required

environment

The handle of the environment to delete.

Yes

Options#

Option

Description

Required

Default

-o <id>, --organization <id>

The ID of the organization that the environment belongs to.

Yes

Falls back to the organization in the active context, if set.

-p <id-or-handle>, --project <id-or-handle>

The ID or handle of the project that the environment belongs to.

Yes

Falls back to the project in the active context, if set.

-y, --yes

Skip the confirmation prompt. Use this in scripts and pipelines where interactive input is not possible.

No

false

--json

Print the result as JSON instead of formatted text.

No

false


environments redeploy#

Redeploy an environment using its current active deployment build. This is useful when you want to roll back to a previous deployment or re-run the active deployment without triggering a new build.

The environment must already have an active deployment. If it doesn't, run mcloud environments trigger-build first to create one.

Arguments#

Option

Description

Required

environment

The handle of the environment to redeploy.

Yes

Options#

Option

Description

Required

Default

-o <id>, --organization <id>

The ID of the organization that the environment belongs to.

Yes

Falls back to the organization in the active context, if set.

-p <id-or-handle>, --project <id-or-handle>

The ID or handle of the project that the environment belongs to.

Yes

Falls back to the project in the active context, if set.

--json

Print the result as JSON instead of formatted text.

No

false


environments trigger-build#

Start a new build for an environment from its tracked branch. This is the equivalent of pushing a commit to the tracked branch but without requiring a Git push.

Arguments#

Option

Description

Required

environment

The handle of the environment to build.

Yes

Options#

Option

Description

Required

Default

-o <id>, --organization <id>

The ID of the organization that the environment belongs to.

Yes

Falls back to the organization in the active context, if set.

-p <id-or-handle>, --project <id-or-handle>

The ID or handle of the project that the environment belongs to.

Yes

Falls back to the project in the active context, if set.

--json

Print the result as JSON instead of formatted text.

No

false


Find Environment Handles#

Commands that operate on environments require an environment handle. You can either:

  • Use the interactive selector in mcloud use to set an active environment for the current context. Once set, you can omit the --environment flag from all subsequent commands;
  • Or use environments list --json to get machine-readable environment data. Pipe the output to jq to extract handles for use in subsequent commands. This is useful if you want to set the active environment through an AI agent, script, or CI/CD pipeline.

For example, to set the first environment in the list as the active environment:

To set an environment by name as the active environment:

Once set, you can omit the --environment flag from all subsequent commands.


Manage Environments in a CI/CD Pipeline#

You can provision and tear down environments automatically as branches are created and deleted in your repository. This is useful for staging environments that mirror production, or for short-lived feature-branch environments used for testing and review.

For example, the following GitHub Actions workflow:

  • Creates a Cloud environment when a branch is pushed
  • Deletes it when the branch is removed.
.github/workflows/cloud-environments.yml
1name: Cloud Environments2
3on:4  create:5    branches-ignore:6      - main7  delete:8    branches-ignore:9      - main10
11env:12  MCLOUD_TOKEN: ${{ secrets.MCLOUD_TOKEN }}13
14jobs:15  create-environment:16    if: github.event_name == 'create' && github.event.ref_type == 'branch'17    runs-on: ubuntu-latest18    steps:19      - name: Install the Cloud CLI20        run: npm install -g @medusajs/mcloud21
22      - name: Create Cloud environment23        run: |24          mcloud environments create \25            --organization org_123 \26            --project proj_123 \27            --name "${{ github.event.ref }}" \28            --branch "${{ github.event.ref }}" \29            --custom-subdomain "my-store-${{ github.event.ref }}"30
31  delete-environment:32    if: github.event_name == 'delete' && github.event.ref_type == 'branch'33    runs-on: ubuntu-latest34    steps:35      - name: Install the Cloud CLI36        run: npm install -g @medusajs/mcloud37
38      - name: Delete Cloud environment39        run: |40          mcloud environments delete "${{ github.event.ref }}" \41            --organization org_123 \42            --project proj_123 \43            --yes

The create-environment job runs mcloud environments create with the branch name as both the environment name and tracked branch. The delete-environment job runs mcloud environments delete with --yes to skip the confirmation prompt, which is required for non-interactive environments like CI runners.

Was this guide helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Medusa MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break