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 |
|---|---|---|---|
| The ID of the organization that the project belongs to. | Yes | Falls back to the organization in the active context, if set. |
| The ID or handle of the project to list environments from. | Yes | Falls back to the project in the active context, if set. |
| Print the result as JSON instead of formatted text. | No |
|
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 |
|---|---|---|
| The handle of the environment to retrieve. | Yes |
Options#
Option | Description | Required | Default |
|---|---|---|---|
| The ID of the organization that the environment belongs to. | Yes | Falls back to the organization in the active context, if set. |
| The ID or handle of the project that the environment belongs to. | Yes | Falls back to the project in the active context, if set. |
| Print the result as JSON instead of formatted text. | No |
|
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 |
|---|---|---|---|
| The ID of the organization to create the environment in. | Yes | Falls back to the organization in the active context, if set. |
| The ID or handle of the project to create the environment in. | Yes | Falls back to the project in the active context, if set. |
| Display name for the new environment. | Yes | - |
| The Git branch this environment tracks. Pushes to this branch trigger new deployments. | Yes | - |
| Custom subdomain for the environment's URL. | No | - |
| Print the result as JSON instead of formatted text. | No |
|
environments delete#
Delete an environment by its handle.
Arguments#
Option | Description | Required |
|---|---|---|
| The handle of the environment to delete. | Yes |
Options#
Option | Description | Required | Default |
|---|---|---|---|
| The ID of the organization that the environment belongs to. | Yes | Falls back to the organization in the active context, if set. |
| The ID or handle of the project that the environment belongs to. | Yes | Falls back to the project in the active context, if set. |
| Skip the confirmation prompt. Use this in scripts and pipelines where interactive input is not possible. | No |
|
| Print the result as JSON instead of formatted text. | No |
|
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 |
|---|---|---|
| The handle of the environment to redeploy. | Yes |
Options#
Option | Description | Required | Default |
|---|---|---|---|
| The ID of the organization that the environment belongs to. | Yes | Falls back to the organization in the active context, if set. |
| The ID or handle of the project that the environment belongs to. | Yes | Falls back to the project in the active context, if set. |
| Print the result as JSON instead of formatted text. | No |
|
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 |
|---|---|---|
| The handle of the environment to build. | Yes |
Options#
Option | Description | Required | Default |
|---|---|---|---|
| The ID of the organization that the environment belongs to. | Yes | Falls back to the organization in the active context, if set. |
| The ID or handle of the project that the environment belongs to. | Yes | Falls back to the project in the active context, if set. |
| Print the result as JSON instead of formatted text. | No |
|
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
--environmentflag from all subsequent commands; - Or use
environments list --jsonto get machine-readable environment data. Pipe the output tojqto 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.
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.