|
1
|
import { Table, Note, CodeTabs, CodeTab } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `environments Command - Medusa Cloud CLI Reference`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
In this guide, you'll learn how to manage your Cloud environments using the CLI. |
|
10
|
|
|
11
|
## environments list |
|
12
|
|
|
13
|
List all environments in a project. |
|
14
|
|
|
15
|
<CodeTabs group="cli-auth"> |
|
16
|
<CodeTab label="With Flags" value="flags"> |
|
17
|
|
|
18
|
```bash |
|
19
|
mcloud environments list --organization org_123 --project proj_123 |
|
20
|
``` |
|
21
|
|
|
22
|
</CodeTab> |
|
23
|
<CodeTab label="Using mcloud use" value="use"> |
|
24
|
|
|
25
|
```bash |
|
26
|
# Run once: mcloud use --organization org_123 --project proj_123 |
|
27
|
|
|
28
|
mcloud environments list |
|
29
|
``` |
|
30
|
|
|
31
|
</CodeTab> |
|
32
|
</CodeTabs> |
|
33
|
|
|
34
|
### Options |
|
35
|
|
|
36
|
<Table> |
|
37
|
<Table.Header> |
|
38
|
<Table.Row> |
|
39
|
<Table.HeaderCell> |
|
40
|
Option |
|
41
|
</Table.HeaderCell> |
|
42
|
<Table.HeaderCell> |
|
43
|
Description |
|
44
|
</Table.HeaderCell> |
|
45
|
<Table.HeaderCell> |
|
46
|
Required |
|
47
|
</Table.HeaderCell> |
|
48
|
<Table.HeaderCell> |
|
49
|
Default |
|
50
|
</Table.HeaderCell> |
|
51
|
</Table.Row> |
|
52
|
</Table.Header> |
|
53
|
<Table.Body> |
|
54
|
<Table.Row> |
|
55
|
<Table.Cell> |
|
56
|
|
|
57
|
`-o <id>`, `--organization <id>` |
|
58
|
|
|
59
|
</Table.Cell> |
|
60
|
<Table.Cell> |
|
61
|
|
|
62
|
The [ID of the organization](../organizations/page.mdx#find-organization-id) that the project belongs to. |
|
63
|
|
|
64
|
</Table.Cell> |
|
65
|
<Table.Cell> |
|
66
|
|
|
67
|
Yes |
|
68
|
|
|
69
|
</Table.Cell> |
|
70
|
<Table.Cell> |
|
71
|
|
|
72
|
Falls back to the organization in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
73
|
|
|
74
|
</Table.Cell> |
|
75
|
</Table.Row> |
|
76
|
<Table.Row> |
|
77
|
<Table.Cell> |
|
78
|
|
|
79
|
`-p <id-or-handle>`, `--project <id-or-handle>` |
|
80
|
|
|
81
|
</Table.Cell> |
|
82
|
<Table.Cell> |
|
83
|
|
|
84
|
The [ID or handle of the project](../projects/page.mdx#find-project-ids-and-handles) to list environments from. |
|
85
|
|
|
86
|
</Table.Cell> |
|
87
|
<Table.Cell> |
|
88
|
|
|
89
|
Yes |
|
90
|
|
|
91
|
</Table.Cell> |
|
92
|
<Table.Cell> |
|
93
|
|
|
94
|
Falls back to the project in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
95
|
|
|
96
|
</Table.Cell> |
|
97
|
</Table.Row> |
|
98
|
<Table.Row> |
|
99
|
<Table.Cell> |
|
100
|
|
|
101
|
`--json` |
|
102
|
|
|
103
|
</Table.Cell> |
|
104
|
<Table.Cell> |
|
105
|
|
|
106
|
Print the result as JSON instead of formatted text. |
|
107
|
|
|
108
|
</Table.Cell> |
|
109
|
<Table.Cell> |
|
110
|
|
|
111
|
No |
|
112
|
|
|
113
|
</Table.Cell> |
|
114
|
<Table.Cell> |
|
115
|
|
|
116
|
`false` |
|
117
|
|
|
118
|
</Table.Cell> |
|
119
|
</Table.Row> |
|
120
|
</Table.Body> |
|
121
|
</Table> |
|
122
|
|
|
123
|
--- |
|
124
|
|
|
125
|
## environments get |
|
126
|
|
|
127
|
Retrieve a single environment by its ID, handle, or name. This is useful if you want to retrieve the environment's details, such as its status or tracked branch. |
|
128
|
|
|
129
|
<CodeTabs group="cli-auth"> |
|
130
|
<CodeTab label="With Flags" value="flags"> |
|
131
|
|
|
132
|
```bash |
|
133
|
mcloud environments get <environment> --organization org_123 --project proj_123 |
|
134
|
``` |
|
135
|
|
|
136
|
</CodeTab> |
|
137
|
<CodeTab label="Using mcloud use" value="use"> |
|
138
|
|
|
139
|
```bash |
|
140
|
# Run once: mcloud use --organization org_123 --project proj_123 |
|
141
|
|
|
142
|
mcloud environments get <environment> |
|
143
|
``` |
|
144
|
|
|
145
|
</CodeTab> |
|
146
|
</CodeTabs> |
|
147
|
|
|
148
|
Returns the following information: |
|
149
|
|
|
150
|
<CodeTabs group="cli-output"> |
|
151
|
<CodeTab label="Plaintext" value="plaintext"> |
|
152
|
|
|
153
|
```bash |
|
154
|
Name: Production |
|
155
|
Handle: <environment-handle> |
|
156
|
Type: production |
|
157
|
Status: ready |
|
158
|
Medusa domain: https://trusting-soft-form.medusajs.app |
|
159
|
Custom domain: https://acme.com |
|
160
|
Tracked branch: main |
|
161
|
Project Name: My Store |
|
162
|
Project Handle: <project-handle> |
|
163
|
Created at: Apr 1, 2026, 11:44 AM GMT+2 |
|
164
|
``` |
|
165
|
|
|
166
|
</CodeTab> |
|
167
|
<CodeTab label="JSON (--json)" value="json"> |
|
168
|
|
|
169
|
```json |
|
170
|
{ |
|
171
|
"id": "<environment-id>", |
|
172
|
"project_id": "<project-id>", |
|
173
|
"handle": "<environment-handle>", |
|
174
|
"name": "Production", |
|
175
|
"type": "production", |
|
176
|
"default_subdomain": "trusting-soft-form", |
|
177
|
"custom_subdomain": "acme", |
|
178
|
"default_domain": "trusting-soft-form.medusajs.app", |
|
179
|
"custom_domain": "acme.com", |
|
180
|
"created_at": "2024-10-10T08:24:32.382Z", |
|
181
|
"updated_at": "2024-10-10T08:24:32.382Z", |
|
182
|
"external_id": "main", |
|
183
|
"status": "ready", |
|
184
|
"metadata": null, |
|
185
|
"project": { |
|
186
|
"id": "<project-id>", |
|
187
|
"name": "My Store", |
|
188
|
"handle": "<project-handle>", |
|
189
|
"region": "us-east-1", |
|
190
|
"organization_id": "<organization-id>", |
|
191
|
"repository": "myuser/my-repo", |
|
192
|
"root_path": "/apps/backend", |
|
193
|
"status": "ready", |
|
194
|
"created_by": "<user-id>", |
|
195
|
"created_at": "2024-10-10T08:24:32.382Z", |
|
196
|
"updated_at": "2024-10-10T08:24:32.382Z", |
|
197
|
"deleted_at": null, |
|
198
|
"metadata": { |
|
199
|
"arch": "arm64" |
|
200
|
}, |
|
201
|
"builds": [], |
|
202
|
"environments": [] |
|
203
|
}, |
|
204
|
"builds": [], |
|
205
|
"deployments": [], |
|
206
|
"variables": [], |
|
207
|
"configuration": { |
|
208
|
"read_replica_database_url": "postgresql://<user>:<password>@<host>/<database>?channel_binding=require&sslmode=require", |
|
209
|
"tent_handle": "<tent-handle>", |
|
210
|
"s3_file_url": "https://s3.us-east-1.amazonaws.com/<bucket>", |
|
211
|
"s3_endpoint": "https://s3.us-east-1.amazonaws.com", |
|
212
|
"upstash_external_id": "<upstash-id>" |
|
213
|
}, |
|
214
|
"rules": null, |
|
215
|
"active_deployment": null |
|
216
|
} |
|
217
|
``` |
|
218
|
|
|
219
|
</CodeTab> |
|
220
|
</CodeTabs> |
|
221
|
|
|
222
|
### Arguments |
|
223
|
|
|
224
|
<Table> |
|
225
|
<Table.Header> |
|
226
|
<Table.Row> |
|
227
|
<Table.HeaderCell> |
|
228
|
Option |
|
229
|
</Table.HeaderCell> |
|
230
|
<Table.HeaderCell> |
|
231
|
Description |
|
232
|
</Table.HeaderCell> |
|
233
|
<Table.HeaderCell> |
|
234
|
Required |
|
235
|
</Table.HeaderCell> |
|
236
|
<Table.HeaderCell> |
|
237
|
Default |
|
238
|
</Table.HeaderCell> |
|
239
|
</Table.Row> |
|
240
|
</Table.Header> |
|
241
|
<Table.Body> |
|
242
|
<Table.Row> |
|
243
|
<Table.Cell> |
|
244
|
|
|
245
|
`environment` |
|
246
|
|
|
247
|
</Table.Cell> |
|
248
|
<Table.Cell> |
|
249
|
|
|
250
|
The ID, handle, or name of the environment to retrieve. |
|
251
|
|
|
252
|
</Table.Cell> |
|
253
|
<Table.Cell> |
|
254
|
|
|
255
|
No |
|
256
|
|
|
257
|
</Table.Cell> |
|
258
|
<Table.Cell> |
|
259
|
|
|
260
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
261
|
|
|
262
|
</Table.Cell> |
|
263
|
</Table.Row> |
|
264
|
</Table.Body> |
|
265
|
</Table> |
|
266
|
|
|
267
|
### Options |
|
268
|
|
|
269
|
<Table> |
|
270
|
<Table.Header> |
|
271
|
<Table.Row> |
|
272
|
<Table.HeaderCell> |
|
273
|
Option |
|
274
|
</Table.HeaderCell> |
|
275
|
<Table.HeaderCell> |
|
276
|
Description |
|
277
|
</Table.HeaderCell> |
|
278
|
<Table.HeaderCell> |
|
279
|
Required |
|
280
|
</Table.HeaderCell> |
|
281
|
<Table.HeaderCell> |
|
282
|
Default |
|
283
|
</Table.HeaderCell> |
|
284
|
</Table.Row> |
|
285
|
</Table.Header> |
|
286
|
<Table.Body> |
|
287
|
<Table.Row> |
|
288
|
<Table.Cell> |
|
289
|
|
|
290
|
`-e <id-handle-or-name>`, `--environment <id-handle-or-name>` |
|
291
|
|
|
292
|
</Table.Cell> |
|
293
|
<Table.Cell> |
|
294
|
|
|
295
|
The ID, handle, or name of the environment to retrieve. Interchangeable with the positional argument. |
|
296
|
|
|
297
|
</Table.Cell> |
|
298
|
<Table.Cell> |
|
299
|
|
|
300
|
No |
|
301
|
|
|
302
|
</Table.Cell> |
|
303
|
<Table.Cell> |
|
304
|
|
|
305
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
306
|
|
|
307
|
</Table.Cell> |
|
308
|
</Table.Row> |
|
309
|
<Table.Row> |
|
310
|
<Table.Cell> |
|
311
|
|
|
312
|
`-o <id>`, `--organization <id>` |
|
313
|
|
|
314
|
</Table.Cell> |
|
315
|
<Table.Cell> |
|
316
|
|
|
317
|
The [ID of the organization](../organizations/page.mdx#find-organization-id) that the environment belongs to. |
|
318
|
|
|
319
|
</Table.Cell> |
|
320
|
<Table.Cell> |
|
321
|
|
|
322
|
Yes |
|
323
|
|
|
324
|
</Table.Cell> |
|
325
|
<Table.Cell> |
|
326
|
|
|
327
|
Falls back to the organization in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
328
|
|
|
329
|
</Table.Cell> |
|
330
|
</Table.Row> |
|
331
|
<Table.Row> |
|
332
|
<Table.Cell> |
|
333
|
|
|
334
|
`-p <id-or-handle>`, `--project <id-or-handle>` |
|
335
|
|
|
336
|
</Table.Cell> |
|
337
|
<Table.Cell> |
|
338
|
|
|
339
|
The [ID or handle of the project](../projects/page.mdx#find-project-ids-and-handles) that the environment belongs to. |
|
340
|
|
|
341
|
</Table.Cell> |
|
342
|
<Table.Cell> |
|
343
|
|
|
344
|
Yes |
|
345
|
|
|
346
|
</Table.Cell> |
|
347
|
<Table.Cell> |
|
348
|
|
|
349
|
Falls back to the project in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
350
|
|
|
351
|
</Table.Cell> |
|
352
|
</Table.Row> |
|
353
|
<Table.Row> |
|
354
|
<Table.Cell> |
|
355
|
|
|
356
|
`--json` |
|
357
|
|
|
358
|
</Table.Cell> |
|
359
|
<Table.Cell> |
|
360
|
|
|
361
|
Print the result as JSON instead of formatted text. |
|
362
|
|
|
363
|
</Table.Cell> |
|
364
|
<Table.Cell> |
|
365
|
|
|
366
|
No |
|
367
|
|
|
368
|
</Table.Cell> |
|
369
|
<Table.Cell> |
|
370
|
|
|
371
|
`false` |
|
372
|
|
|
373
|
</Table.Cell> |
|
374
|
</Table.Row> |
|
375
|
</Table.Body> |
|
376
|
</Table> |
|
377
|
|
|
378
|
--- |
|
379
|
|
|
380
|
## environments create |
|
381
|
|
|
382
|
Create a new [long-lived environment](../../../environments/long-lived/page.mdx) 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. |
|
383
|
|
|
384
|
<CodeTabs group="cli-auth"> |
|
385
|
<CodeTab label="With Flags" value="flags"> |
|
386
|
|
|
387
|
```bash |
|
388
|
mcloud environments create \ |
|
389
|
--organization org_123 \ |
|
390
|
--project proj_123 \ |
|
391
|
--name "Staging" \ |
|
392
|
--branch develop |
|
393
|
``` |
|
394
|
|
|
395
|
</CodeTab> |
|
396
|
<CodeTab label="Using mcloud use" value="use"> |
|
397
|
|
|
398
|
```bash |
|
399
|
# Run once: mcloud use --organization org_123 --project proj_123 |
|
400
|
|
|
401
|
mcloud environments create \ |
|
402
|
--name "Staging" \ |
|
403
|
--branch develop |
|
404
|
``` |
|
405
|
|
|
406
|
</CodeTab> |
|
407
|
</CodeTabs> |
|
408
|
|
|
409
|
### Options |
|
410
|
|
|
411
|
<Table> |
|
412
|
<Table.Header> |
|
413
|
<Table.Row> |
|
414
|
<Table.HeaderCell> |
|
415
|
Option |
|
416
|
</Table.HeaderCell> |
|
417
|
<Table.HeaderCell> |
|
418
|
Description |
|
419
|
</Table.HeaderCell> |
|
420
|
<Table.HeaderCell> |
|
421
|
Required |
|
422
|
</Table.HeaderCell> |
|
423
|
<Table.HeaderCell> |
|
424
|
Default |
|
425
|
</Table.HeaderCell> |
|
426
|
</Table.Row> |
|
427
|
</Table.Header> |
|
428
|
<Table.Body> |
|
429
|
<Table.Row> |
|
430
|
<Table.Cell> |
|
431
|
|
|
432
|
`-o <id>`, `--organization <id>` |
|
433
|
|
|
434
|
</Table.Cell> |
|
435
|
<Table.Cell> |
|
436
|
|
|
437
|
The [ID of the organization](../organizations/page.mdx#find-organization-id) to create the environment in. |
|
438
|
|
|
439
|
</Table.Cell> |
|
440
|
<Table.Cell> |
|
441
|
|
|
442
|
Yes |
|
443
|
|
|
444
|
</Table.Cell> |
|
445
|
<Table.Cell> |
|
446
|
|
|
447
|
Falls back to the organization in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
448
|
|
|
449
|
</Table.Cell> |
|
450
|
</Table.Row> |
|
451
|
<Table.Row> |
|
452
|
<Table.Cell> |
|
453
|
|
|
454
|
`-p <id-or-handle>`, `--project <id-or-handle>` |
|
455
|
|
|
456
|
</Table.Cell> |
|
457
|
<Table.Cell> |
|
458
|
|
|
459
|
The [ID or handle of the project](../projects/page.mdx#find-project-ids-and-handles) to create the environment in. |
|
460
|
|
|
461
|
</Table.Cell> |
|
462
|
<Table.Cell> |
|
463
|
|
|
464
|
Yes |
|
465
|
|
|
466
|
</Table.Cell> |
|
467
|
<Table.Cell> |
|
468
|
|
|
469
|
Falls back to the project in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
470
|
|
|
471
|
</Table.Cell> |
|
472
|
</Table.Row> |
|
473
|
<Table.Row> |
|
474
|
<Table.Cell> |
|
475
|
|
|
476
|
`-n <name>`, `--name <name>` |
|
477
|
|
|
478
|
</Table.Cell> |
|
479
|
<Table.Cell> |
|
480
|
|
|
481
|
Display name for the new environment. |
|
482
|
|
|
483
|
</Table.Cell> |
|
484
|
<Table.Cell> |
|
485
|
|
|
486
|
Yes |
|
487
|
|
|
488
|
</Table.Cell> |
|
489
|
<Table.Cell> |
|
490
|
|
|
491
|
\- |
|
492
|
|
|
493
|
</Table.Cell> |
|
494
|
</Table.Row> |
|
495
|
<Table.Row> |
|
496
|
<Table.Cell> |
|
497
|
|
|
498
|
`-b <branch>`, `--branch <branch>` |
|
499
|
|
|
500
|
</Table.Cell> |
|
501
|
<Table.Cell> |
|
502
|
|
|
503
|
The Git branch this environment tracks. Pushes to this branch trigger |
|
504
|
new deployments. |
|
505
|
|
|
506
|
</Table.Cell> |
|
507
|
<Table.Cell> |
|
508
|
|
|
509
|
Yes |
|
510
|
|
|
511
|
</Table.Cell> |
|
512
|
<Table.Cell> |
|
513
|
|
|
514
|
\- |
|
515
|
|
|
516
|
</Table.Cell> |
|
517
|
</Table.Row> |
|
518
|
<Table.Row> |
|
519
|
<Table.Cell> |
|
520
|
|
|
521
|
`--custom-subdomain <subdomain>` |
|
522
|
|
|
523
|
</Table.Cell> |
|
524
|
<Table.Cell> |
|
525
|
|
|
526
|
[Custom subdomain](../../../environments/subdomains/page.mdx) for the environment's URL. |
|
527
|
|
|
528
|
</Table.Cell> |
|
529
|
<Table.Cell> |
|
530
|
|
|
531
|
No |
|
532
|
|
|
533
|
</Table.Cell> |
|
534
|
<Table.Cell> |
|
535
|
|
|
536
|
\- |
|
537
|
|
|
538
|
</Table.Cell> |
|
539
|
</Table.Row> |
|
540
|
<Table.Row> |
|
541
|
<Table.Cell> |
|
542
|
|
|
543
|
`--json` |
|
544
|
|
|
545
|
</Table.Cell> |
|
546
|
<Table.Cell> |
|
547
|
|
|
548
|
Print the result as JSON instead of formatted text. |
|
549
|
|
|
550
|
</Table.Cell> |
|
551
|
<Table.Cell> |
|
552
|
|
|
553
|
No |
|
554
|
|
|
555
|
</Table.Cell> |
|
556
|
<Table.Cell> |
|
557
|
|
|
558
|
`false` |
|
559
|
|
|
560
|
</Table.Cell> |
|
561
|
</Table.Row> |
|
562
|
</Table.Body> |
|
563
|
</Table> |
|
564
|
|
|
565
|
--- |
|
566
|
|
|
567
|
## environments delete |
|
568
|
|
|
569
|
Delete an environment by its ID, handle, or name. |
|
570
|
|
|
571
|
<Note type="warning"> |
|
572
|
|
|
573
|
Deleting an environment is irreversible and removes all associated |
|
574
|
deployments and resources. Production environments cannot be deleted. |
|
575
|
|
|
576
|
</Note> |
|
577
|
|
|
578
|
<CodeTabs group="cli-auth"> |
|
579
|
<CodeTab label="With Flags" value="flags"> |
|
580
|
|
|
581
|
```bash |
|
582
|
mcloud environments delete <environment> --organization org_123 --project proj_123 |
|
583
|
``` |
|
584
|
|
|
585
|
</CodeTab> |
|
586
|
<CodeTab label="Using mcloud use" value="use"> |
|
587
|
|
|
588
|
```bash |
|
589
|
# Run once: mcloud use --organization org_123 --project proj_123 |
|
590
|
|
|
591
|
mcloud environments delete <environment> |
|
592
|
``` |
|
593
|
|
|
594
|
</CodeTab> |
|
595
|
</CodeTabs> |
|
596
|
|
|
597
|
### Arguments |
|
598
|
|
|
599
|
<Table> |
|
600
|
<Table.Header> |
|
601
|
<Table.Row> |
|
602
|
<Table.HeaderCell> |
|
603
|
Option |
|
604
|
</Table.HeaderCell> |
|
605
|
<Table.HeaderCell> |
|
606
|
Description |
|
607
|
</Table.HeaderCell> |
|
608
|
<Table.HeaderCell> |
|
609
|
Required |
|
610
|
</Table.HeaderCell> |
|
611
|
<Table.HeaderCell> |
|
612
|
Default |
|
613
|
</Table.HeaderCell> |
|
614
|
</Table.Row> |
|
615
|
</Table.Header> |
|
616
|
<Table.Body> |
|
617
|
<Table.Row> |
|
618
|
<Table.Cell> |
|
619
|
|
|
620
|
`environment` |
|
621
|
|
|
622
|
</Table.Cell> |
|
623
|
<Table.Cell> |
|
624
|
|
|
625
|
The ID, handle, or name of the environment to delete. |
|
626
|
|
|
627
|
</Table.Cell> |
|
628
|
<Table.Cell> |
|
629
|
|
|
630
|
No |
|
631
|
|
|
632
|
</Table.Cell> |
|
633
|
<Table.Cell> |
|
634
|
|
|
635
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
636
|
|
|
637
|
</Table.Cell> |
|
638
|
</Table.Row> |
|
639
|
</Table.Body> |
|
640
|
</Table> |
|
641
|
|
|
642
|
### Options |
|
643
|
|
|
644
|
<Table> |
|
645
|
<Table.Header> |
|
646
|
<Table.Row> |
|
647
|
<Table.HeaderCell> |
|
648
|
Option |
|
649
|
</Table.HeaderCell> |
|
650
|
<Table.HeaderCell> |
|
651
|
Description |
|
652
|
</Table.HeaderCell> |
|
653
|
<Table.HeaderCell> |
|
654
|
Required |
|
655
|
</Table.HeaderCell> |
|
656
|
<Table.HeaderCell> |
|
657
|
Default |
|
658
|
</Table.HeaderCell> |
|
659
|
</Table.Row> |
|
660
|
</Table.Header> |
|
661
|
<Table.Body> |
|
662
|
<Table.Row> |
|
663
|
<Table.Cell> |
|
664
|
|
|
665
|
`-e <id-handle-or-name>`, `--environment <id-handle-or-name>` |
|
666
|
|
|
667
|
</Table.Cell> |
|
668
|
<Table.Cell> |
|
669
|
|
|
670
|
The ID, handle, or name of the environment to delete. Interchangeable with the positional argument. |
|
671
|
|
|
672
|
</Table.Cell> |
|
673
|
<Table.Cell> |
|
674
|
|
|
675
|
No |
|
676
|
|
|
677
|
</Table.Cell> |
|
678
|
<Table.Cell> |
|
679
|
|
|
680
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
681
|
|
|
682
|
</Table.Cell> |
|
683
|
</Table.Row> |
|
684
|
<Table.Row> |
|
685
|
<Table.Cell> |
|
686
|
|
|
687
|
`-o <id>`, `--organization <id>` |
|
688
|
|
|
689
|
</Table.Cell> |
|
690
|
<Table.Cell> |
|
691
|
|
|
692
|
The [ID of the organization](../organizations/page.mdx#find-organization-id) that the environment belongs to. |
|
693
|
|
|
694
|
</Table.Cell> |
|
695
|
<Table.Cell> |
|
696
|
|
|
697
|
Yes |
|
698
|
|
|
699
|
</Table.Cell> |
|
700
|
<Table.Cell> |
|
701
|
|
|
702
|
Falls back to the organization in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
703
|
|
|
704
|
</Table.Cell> |
|
705
|
</Table.Row> |
|
706
|
<Table.Row> |
|
707
|
<Table.Cell> |
|
708
|
|
|
709
|
`-p <id-or-handle>`, `--project <id-or-handle>` |
|
710
|
|
|
711
|
</Table.Cell> |
|
712
|
<Table.Cell> |
|
713
|
|
|
714
|
The [ID or handle of the project](../projects/page.mdx#find-project-ids-and-handles) that the environment belongs to. |
|
715
|
|
|
716
|
</Table.Cell> |
|
717
|
<Table.Cell> |
|
718
|
|
|
719
|
Yes |
|
720
|
|
|
721
|
</Table.Cell> |
|
722
|
<Table.Cell> |
|
723
|
|
|
724
|
Falls back to the project in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
725
|
|
|
726
|
</Table.Cell> |
|
727
|
</Table.Row> |
|
728
|
<Table.Row> |
|
729
|
<Table.Cell> |
|
730
|
|
|
731
|
`-y`, `--yes` |
|
732
|
|
|
733
|
</Table.Cell> |
|
734
|
<Table.Cell> |
|
735
|
|
|
736
|
Skip the confirmation prompt. Use this in scripts and pipelines where |
|
737
|
interactive input is not possible. |
|
738
|
|
|
739
|
</Table.Cell> |
|
740
|
<Table.Cell> |
|
741
|
|
|
742
|
No |
|
743
|
|
|
744
|
</Table.Cell> |
|
745
|
<Table.Cell> |
|
746
|
|
|
747
|
`false` |
|
748
|
|
|
749
|
</Table.Cell> |
|
750
|
</Table.Row> |
|
751
|
<Table.Row> |
|
752
|
<Table.Cell> |
|
753
|
|
|
754
|
`--json` |
|
755
|
|
|
756
|
</Table.Cell> |
|
757
|
<Table.Cell> |
|
758
|
|
|
759
|
Print the result as JSON instead of formatted text. |
|
760
|
|
|
761
|
</Table.Cell> |
|
762
|
<Table.Cell> |
|
763
|
|
|
764
|
No |
|
765
|
|
|
766
|
</Table.Cell> |
|
767
|
<Table.Cell> |
|
768
|
|
|
769
|
`false` |
|
770
|
|
|
771
|
</Table.Cell> |
|
772
|
</Table.Row> |
|
773
|
</Table.Body> |
|
774
|
</Table> |
|
775
|
|
|
776
|
--- |
|
777
|
|
|
778
|
## environments redeploy |
|
779
|
|
|
780
|
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. |
|
781
|
|
|
782
|
<CodeTabs group="cli-auth"> |
|
783
|
<CodeTab label="With Flags" value="flags"> |
|
784
|
|
|
785
|
```bash |
|
786
|
mcloud environments redeploy <environment> --organization org_123 --project proj_123 |
|
787
|
``` |
|
788
|
|
|
789
|
</CodeTab> |
|
790
|
<CodeTab label="Using mcloud use" value="use"> |
|
791
|
|
|
792
|
```bash |
|
793
|
# Run once: mcloud use --organization org_123 --project proj_123 |
|
794
|
|
|
795
|
mcloud environments redeploy <environment> |
|
796
|
``` |
|
797
|
|
|
798
|
</CodeTab> |
|
799
|
</CodeTabs> |
|
800
|
|
|
801
|
The environment must already have an active deployment. If it doesn't, run [`mcloud environments trigger-build`](#environments-trigger-build) first to create one. |
|
802
|
|
|
803
|
### Arguments |
|
804
|
|
|
805
|
<Table> |
|
806
|
<Table.Header> |
|
807
|
<Table.Row> |
|
808
|
<Table.HeaderCell> |
|
809
|
Option |
|
810
|
</Table.HeaderCell> |
|
811
|
<Table.HeaderCell> |
|
812
|
Description |
|
813
|
</Table.HeaderCell> |
|
814
|
<Table.HeaderCell> |
|
815
|
Required |
|
816
|
</Table.HeaderCell> |
|
817
|
<Table.HeaderCell> |
|
818
|
Default |
|
819
|
</Table.HeaderCell> |
|
820
|
</Table.Row> |
|
821
|
</Table.Header> |
|
822
|
<Table.Body> |
|
823
|
<Table.Row> |
|
824
|
<Table.Cell> |
|
825
|
|
|
826
|
`environment` |
|
827
|
|
|
828
|
</Table.Cell> |
|
829
|
<Table.Cell> |
|
830
|
|
|
831
|
The ID, handle, or name of the environment to redeploy. |
|
832
|
|
|
833
|
</Table.Cell> |
|
834
|
<Table.Cell> |
|
835
|
|
|
836
|
No |
|
837
|
|
|
838
|
</Table.Cell> |
|
839
|
<Table.Cell> |
|
840
|
|
|
841
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
842
|
|
|
843
|
</Table.Cell> |
|
844
|
</Table.Row> |
|
845
|
</Table.Body> |
|
846
|
</Table> |
|
847
|
|
|
848
|
### Options |
|
849
|
|
|
850
|
<Table> |
|
851
|
<Table.Header> |
|
852
|
<Table.Row> |
|
853
|
<Table.HeaderCell> |
|
854
|
Option |
|
855
|
</Table.HeaderCell> |
|
856
|
<Table.HeaderCell> |
|
857
|
Description |
|
858
|
</Table.HeaderCell> |
|
859
|
<Table.HeaderCell> |
|
860
|
Required |
|
861
|
</Table.HeaderCell> |
|
862
|
<Table.HeaderCell> |
|
863
|
Default |
|
864
|
</Table.HeaderCell> |
|
865
|
</Table.Row> |
|
866
|
</Table.Header> |
|
867
|
<Table.Body> |
|
868
|
<Table.Row> |
|
869
|
<Table.Cell> |
|
870
|
|
|
871
|
`-e <id-handle-or-name>`, `--environment <id-handle-or-name>` |
|
872
|
|
|
873
|
</Table.Cell> |
|
874
|
<Table.Cell> |
|
875
|
|
|
876
|
The ID, handle, or name of the environment to redeploy. Interchangeable with the positional argument. |
|
877
|
|
|
878
|
</Table.Cell> |
|
879
|
<Table.Cell> |
|
880
|
|
|
881
|
No |
|
882
|
|
|
883
|
</Table.Cell> |
|
884
|
<Table.Cell> |
|
885
|
|
|
886
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
887
|
|
|
888
|
</Table.Cell> |
|
889
|
</Table.Row> |
|
890
|
<Table.Row> |
|
891
|
<Table.Cell> |
|
892
|
|
|
893
|
`-o <id>`, `--organization <id>` |
|
894
|
|
|
895
|
</Table.Cell> |
|
896
|
<Table.Cell> |
|
897
|
|
|
898
|
The [ID of the organization](../organizations/page.mdx#find-organization-id) that the environment belongs to. |
|
899
|
|
|
900
|
</Table.Cell> |
|
901
|
<Table.Cell> |
|
902
|
|
|
903
|
Yes |
|
904
|
|
|
905
|
</Table.Cell> |
|
906
|
<Table.Cell> |
|
907
|
|
|
908
|
Falls back to the organization in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
909
|
|
|
910
|
</Table.Cell> |
|
911
|
</Table.Row> |
|
912
|
<Table.Row> |
|
913
|
<Table.Cell> |
|
914
|
|
|
915
|
`-p <id-or-handle>`, `--project <id-or-handle>` |
|
916
|
|
|
917
|
</Table.Cell> |
|
918
|
<Table.Cell> |
|
919
|
|
|
920
|
The [ID or handle of the project](../projects/page.mdx#find-project-ids-and-handles) that the environment belongs to. |
|
921
|
|
|
922
|
</Table.Cell> |
|
923
|
<Table.Cell> |
|
924
|
|
|
925
|
Yes |
|
926
|
|
|
927
|
</Table.Cell> |
|
928
|
<Table.Cell> |
|
929
|
|
|
930
|
Falls back to the project in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
931
|
|
|
932
|
</Table.Cell> |
|
933
|
</Table.Row> |
|
934
|
<Table.Row> |
|
935
|
<Table.Cell> |
|
936
|
|
|
937
|
`--json` |
|
938
|
|
|
939
|
</Table.Cell> |
|
940
|
<Table.Cell> |
|
941
|
|
|
942
|
Print the result as JSON instead of formatted text. |
|
943
|
|
|
944
|
</Table.Cell> |
|
945
|
<Table.Cell> |
|
946
|
|
|
947
|
No |
|
948
|
|
|
949
|
</Table.Cell> |
|
950
|
<Table.Cell> |
|
951
|
|
|
952
|
`false` |
|
953
|
|
|
954
|
</Table.Cell> |
|
955
|
</Table.Row> |
|
956
|
</Table.Body> |
|
957
|
</Table> |
|
958
|
|
|
959
|
--- |
|
960
|
|
|
961
|
## environments trigger-build |
|
962
|
|
|
963
|
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. |
|
964
|
|
|
965
|
<CodeTabs group="cli-auth"> |
|
966
|
<CodeTab label="With Flags" value="flags"> |
|
967
|
|
|
968
|
```bash |
|
969
|
mcloud environments trigger-build <environment> --organization org_123 --project proj_123 |
|
970
|
``` |
|
971
|
|
|
972
|
</CodeTab> |
|
973
|
<CodeTab label="Using mcloud use" value="use"> |
|
974
|
|
|
975
|
```bash |
|
976
|
# Run once: mcloud use --organization org_123 --project proj_123 |
|
977
|
|
|
978
|
mcloud environments trigger-build <environment> |
|
979
|
``` |
|
980
|
|
|
981
|
</CodeTab> |
|
982
|
</CodeTabs> |
|
983
|
|
|
984
|
### Arguments |
|
985
|
|
|
986
|
<Table> |
|
987
|
<Table.Header> |
|
988
|
<Table.Row> |
|
989
|
<Table.HeaderCell> |
|
990
|
Option |
|
991
|
</Table.HeaderCell> |
|
992
|
<Table.HeaderCell> |
|
993
|
Description |
|
994
|
</Table.HeaderCell> |
|
995
|
<Table.HeaderCell> |
|
996
|
Required |
|
997
|
</Table.HeaderCell> |
|
998
|
<Table.HeaderCell> |
|
999
|
Default |
|
1000
|
</Table.HeaderCell> |
|
1001
|
</Table.Row> |
|
1002
|
</Table.Header> |
|
1003
|
<Table.Body> |
|
1004
|
<Table.Row> |
|
1005
|
<Table.Cell> |
|
1006
|
|
|
1007
|
`environment` |
|
1008
|
|
|
1009
|
</Table.Cell> |
|
1010
|
<Table.Cell> |
|
1011
|
|
|
1012
|
The ID, handle, or name of the environment to build. |
|
1013
|
|
|
1014
|
</Table.Cell> |
|
1015
|
<Table.Cell> |
|
1016
|
|
|
1017
|
No |
|
1018
|
|
|
1019
|
</Table.Cell> |
|
1020
|
<Table.Cell> |
|
1021
|
|
|
1022
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
1023
|
|
|
1024
|
</Table.Cell> |
|
1025
|
</Table.Row> |
|
1026
|
</Table.Body> |
|
1027
|
</Table> |
|
1028
|
|
|
1029
|
### Options |
|
1030
|
|
|
1031
|
<Table> |
|
1032
|
<Table.Header> |
|
1033
|
<Table.Row> |
|
1034
|
<Table.HeaderCell> |
|
1035
|
Option |
|
1036
|
</Table.HeaderCell> |
|
1037
|
<Table.HeaderCell> |
|
1038
|
Description |
|
1039
|
</Table.HeaderCell> |
|
1040
|
<Table.HeaderCell> |
|
1041
|
Required |
|
1042
|
</Table.HeaderCell> |
|
1043
|
<Table.HeaderCell> |
|
1044
|
Default |
|
1045
|
</Table.HeaderCell> |
|
1046
|
</Table.Row> |
|
1047
|
</Table.Header> |
|
1048
|
<Table.Body> |
|
1049
|
<Table.Row> |
|
1050
|
<Table.Cell> |
|
1051
|
|
|
1052
|
`-e <id-handle-or-name>`, `--environment <id-handle-or-name>` |
|
1053
|
|
|
1054
|
</Table.Cell> |
|
1055
|
<Table.Cell> |
|
1056
|
|
|
1057
|
The ID, handle, or name of the environment to build. Interchangeable with the positional argument. |
|
1058
|
|
|
1059
|
</Table.Cell> |
|
1060
|
<Table.Cell> |
|
1061
|
|
|
1062
|
No |
|
1063
|
|
|
1064
|
</Table.Cell> |
|
1065
|
<Table.Cell> |
|
1066
|
|
|
1067
|
Falls back to the environment in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
1068
|
|
|
1069
|
</Table.Cell> |
|
1070
|
</Table.Row> |
|
1071
|
<Table.Row> |
|
1072
|
<Table.Cell> |
|
1073
|
|
|
1074
|
`-o <id>`, `--organization <id>` |
|
1075
|
|
|
1076
|
</Table.Cell> |
|
1077
|
<Table.Cell> |
|
1078
|
|
|
1079
|
The [ID of the organization](../organizations/page.mdx#find-organization-id) that the environment belongs to. |
|
1080
|
|
|
1081
|
</Table.Cell> |
|
1082
|
<Table.Cell> |
|
1083
|
|
|
1084
|
Yes |
|
1085
|
|
|
1086
|
</Table.Cell> |
|
1087
|
<Table.Cell> |
|
1088
|
|
|
1089
|
Falls back to the organization in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
1090
|
|
|
1091
|
</Table.Cell> |
|
1092
|
</Table.Row> |
|
1093
|
<Table.Row> |
|
1094
|
<Table.Cell> |
|
1095
|
|
|
1096
|
`-p <id-or-handle>`, `--project <id-or-handle>` |
|
1097
|
|
|
1098
|
</Table.Cell> |
|
1099
|
<Table.Cell> |
|
1100
|
|
|
1101
|
The [ID or handle of the project](../projects/page.mdx#find-project-ids-and-handles) that the environment belongs to. |
|
1102
|
|
|
1103
|
</Table.Cell> |
|
1104
|
<Table.Cell> |
|
1105
|
|
|
1106
|
Yes |
|
1107
|
|
|
1108
|
</Table.Cell> |
|
1109
|
<Table.Cell> |
|
1110
|
|
|
1111
|
Falls back to the project in the [active context](../use/page.mdx#set-the-active-context), if set. |
|
1112
|
|
|
1113
|
</Table.Cell> |
|
1114
|
</Table.Row> |
|
1115
|
<Table.Row> |
|
1116
|
<Table.Cell> |
|
1117
|
|
|
1118
|
`--json` |
|
1119
|
|
|
1120
|
</Table.Cell> |
|
1121
|
<Table.Cell> |
|
1122
|
|
|
1123
|
Print the result as JSON instead of formatted text. |
|
1124
|
|
|
1125
|
</Table.Cell> |
|
1126
|
<Table.Cell> |
|
1127
|
|
|
1128
|
No |
|
1129
|
|
|
1130
|
</Table.Cell> |
|
1131
|
<Table.Cell> |
|
1132
|
|
|
1133
|
`false` |
|
1134
|
|
|
1135
|
</Table.Cell> |
|
1136
|
</Table.Row> |
|
1137
|
</Table.Body> |
|
1138
|
</Table> |
|
1139
|
|
|
1140
|
--- |
|
1141
|
|
|
1142
|
## Find Environment Handles |
|
1143
|
|
|
1144
|
Commands that operate on environments require an environment handle. You can either: |
|
1145
|
|
|
1146
|
- Use the interactive selector in [mcloud use](../use/page.mdx#set-the-active-context) to set an active environment for the current context. Once set, you can omit the `--environment` flag from all subsequent commands; |
|
1147
|
- 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. |
|
1148
|
|
|
1149
|
For example, to set the first environment in the list as the active environment: |
|
1150
|
|
|
1151
|
<CodeTabs group="os"> |
|
1152
|
<CodeTab label="macOS / Linux" value="unix"> |
|
1153
|
|
|
1154
|
```bash |
|
1155
|
ENVIRONMENT_HANDLE=$( |
|
1156
|
mcloud environments list --json \ |
|
1157
|
| jq -r '.[0].handle' |
|
1158
|
) |
|
1159
|
mcloud use --environment "$ENVIRONMENT_HANDLE" |
|
1160
|
``` |
|
1161
|
|
|
1162
|
</CodeTab> |
|
1163
|
<CodeTab label="Windows (PowerShell)" value="powershell"> |
|
1164
|
|
|
1165
|
```powershell |
|
1166
|
$ENVIRONMENT_HANDLE = ( |
|
1167
|
mcloud environments list --json | |
|
1168
|
jq -r '.[0].handle' |
|
1169
|
) |
|
1170
|
mcloud use --environment $ENVIRONMENT_HANDLE |
|
1171
|
``` |
|
1172
|
|
|
1173
|
</CodeTab> |
|
1174
|
</CodeTabs> |
|
1175
|
|
|
1176
|
To set an environment by name as the active environment: |
|
1177
|
|
|
1178
|
<CodeTabs group="os"> |
|
1179
|
<CodeTab label="macOS / Linux" value="unix"> |
|
1180
|
|
|
1181
|
```bash |
|
1182
|
ENVIRONMENT_HANDLE=$( |
|
1183
|
mcloud environments list --json \ |
|
1184
|
| jq -r '.[] | select(.name == "Staging") | .handle' |
|
1185
|
) |
|
1186
|
mcloud use --environment "$ENVIRONMENT_HANDLE" |
|
1187
|
``` |
|
1188
|
|
|
1189
|
</CodeTab> |
|
1190
|
<CodeTab label="Windows (PowerShell)" value="powershell"> |
|
1191
|
|
|
1192
|
```powershell |
|
1193
|
$ENVIRONMENT_HANDLE = ( |
|
1194
|
mcloud environments list --json | |
|
1195
|
jq -r '.[] | select(.name == "Staging") | .handle' |
|
1196
|
) |
|
1197
|
mcloud use --environment $ENVIRONMENT_HANDLE |
|
1198
|
``` |
|
1199
|
|
|
1200
|
</CodeTab> |
|
1201
|
</CodeTabs> |
|
1202
|
|
|
1203
|
Once set, you can omit the `--environment` flag from all subsequent commands. |
|
1204
|
|
|
1205
|
--- |
|
1206
|
|
|
1207
|
## Manage Environments in a CI/CD Pipeline |
|
1208
|
|
|
1209
|
You can provision and tear down environments automatically as branches are |
|
1210
|
created and deleted in your repository. This is useful for staging |
|
1211
|
environments that mirror production, or for short-lived feature-branch |
|
1212
|
environments used for testing and review. |
|
1213
|
|
|
1214
|
For example, the following GitHub Actions workflow: |
|
1215
|
|
|
1216
|
- Creates a Cloud environment when a branch is pushed |
|
1217
|
- Deletes it when the branch is removed. |
|
1218
|
|
|
1219
|
```yaml title=".github/workflows/cloud-environments.yml" |
|
1220
|
name: Cloud Environments |
|
1221
|
|
|
1222
|
on: |
|
1223
|
create: |
|
1224
|
branches-ignore: |
|
1225
|
- main |
|
1226
|
delete: |
|
1227
|
branches-ignore: |
|
1228
|
- main |
|
1229
|
|
|
1230
|
env: |
|
1231
|
MCLOUD_TOKEN: ${{ secrets.MCLOUD_TOKEN }} |
|
1232
|
|
|
1233
|
jobs: |
|
1234
|
create-environment: |
|
1235
|
if: github.event_name == 'create' && github.event.ref_type == 'branch' |
|
1236
|
runs-on: ubuntu-latest |
|
1237
|
steps: |
|
1238
|
- name: Install the Cloud CLI |
|
1239
|
run: npm install @medusajs/mcloud -g |
|
1240
|
|
|
1241
|
- name: Create Cloud environment |
|
1242
|
run: | |
|
1243
|
mcloud environments create \ |
|
1244
|
--organization org_123 \ |
|
1245
|
--project proj_123 \ |
|
1246
|
--name "${{ github.event.ref }}" \ |
|
1247
|
--branch "${{ github.event.ref }}" \ |
|
1248
|
--custom-subdomain "my-store-${{ github.event.ref }}" |
|
1249
|
|
|
1250
|
delete-environment: |
|
1251
|
if: github.event_name == 'delete' && github.event.ref_type == 'branch' |
|
1252
|
runs-on: ubuntu-latest |
|
1253
|
steps: |
|
1254
|
- name: Install the Cloud CLI |
|
1255
|
run: npm install @medusajs/mcloud -g |
|
1256
|
|
|
1257
|
- name: Delete Cloud environment |
|
1258
|
run: | |
|
1259
|
mcloud environments delete "${{ github.event.ref }}" \ |
|
1260
|
--organization org_123 \ |
|
1261
|
--project proj_123 \ |
|
1262
|
--yes |
|
1263
|
``` |
|
1264
|
|
|
1265
|
The `create-environment` job runs `mcloud environments create` with the |
|
1266
|
branch name as both the environment name and tracked branch. The |
|
1267
|
`delete-environment` job runs `mcloud environments delete` with `--yes` to |
|
1268
|
skip the confirmation prompt, which is required for non-interactive |
|
1269
|
environments like CI runners. |