Skip to content

Commit 70ea83d

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
feat(cli): show the deploy environment, add --prod, and use the API key's environment
`trigger deploy` and `trigger promote` now say which environment they're targeting and accept `--prod` as a shorthand for `--env prod`. When `TRIGGER_ACCESS_TOKEN` holds an environment API key and you don't pass `--env`, they use that key's environment instead of assuming prod. Passing an `--env` that doesn't match the key is now an error. Preview deploys now detect the branch on CI providers that check out a detached HEAD, such as GitLab, Bitbucket, CircleCI, Buildkite, Travis CI, Jenkins and Azure Pipelines. Test links after a preview deploy now open the branch you deployed. The MCP `deploy` tool no longer defaults to prod. The docs and the dashboard's deploy command now pass `--env prod` explicitly. Mono-RevId: 008decd79ebb1b7375e4dfa522a19fb3d97ff32d
1 parent 753ede6 commit 70ea83d

21 files changed

Lines changed: 445 additions & 70 deletions

‎.changeset/deploy-explicit-env.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
`trigger deploy` and `trigger promote` now say which environment they're targeting, and accept `--prod` as a shorthand for `--env prod`. When `TRIGGER_ACCESS_TOKEN` holds an environment API key and you don't pass `--env`, they now use that key's environment instead of assuming prod. Passing an `--env` that doesn't match the key is now an error, where before the deploy went to the key's environment.
7+
8+
Preview deploys now detect the branch on CI providers that check out a detached HEAD, such as GitLab, Bitbucket, CircleCI, Buildkite, Travis CI, Jenkins and Azure Pipelines, instead of creating a branch called `HEAD`. Test links printed after a preview deploy now open the preview branch you deployed instead of staging.
9+
10+
The MCP `deploy` tool no longer defaults to prod, so your AI assistant has to choose the environment.

‎apps/webapp/app/components/SetupCommands.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export function TriggerDeployStep({
235235
return " --env preview";
236236
case "PRODUCTION":
237237
default:
238-
return "";
238+
return " --env prod";
239239
}
240240
};
241241

‎apps/webapp/app/routes/projects.v3.$projectRef.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LoaderFunctionArgs } from "@remix-run/server-runtime";
22
import { redirect } from "@remix-run/server-runtime";
3+
import { sanitizeBranchName } from "@trigger.dev/core/v3/utils/gitBranch";
34
import { z } from "zod";
45
import { prisma } from "~/db.server";
56
import { requireUserId } from "~/services/session.server";
@@ -36,10 +37,28 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
3637

3738
const url = new URL(request.url);
3839
const environment = url.searchParams.get("environment");
40+
const branch = sanitizeBranchName(url.searchParams.get("branch"));
3941

4042
if (environment) {
43+
// The CLI links preview deploys by branch name. Branch environments have their own slug.
44+
const branchEnvironment = branch
45+
? await prisma.runtimeEnvironment.findFirst({
46+
select: { slug: true },
47+
where: {
48+
projectId: project.id,
49+
branchName: branch,
50+
archivedAt: null,
51+
parentEnvironment: { slug: environment, type: "PREVIEW" },
52+
},
53+
})
54+
: null;
55+
4156
return redirect(
42-
v3TestPath({ slug: project.organization.slug }, { slug: project.slug }, { slug: environment })
57+
v3TestPath(
58+
{ slug: project.organization.slug },
59+
{ slug: project.slug },
60+
{ slug: branchEnvironment?.slug ?? environment }
61+
)
4362
);
4463
}
4564

‎docs/apikeys.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ Set a key in `TRIGGER_ACCESS_TOKEN` to authenticate `trigger deploy` without log
9898
<CodeGroup>
9999

100100
```bash npm
101-
TRIGGER_ACCESS_TOKEN="tr_prod_sk_…" npx trigger.dev@latest deploy
101+
TRIGGER_ACCESS_TOKEN="tr_prod_sk_…" npx trigger.dev@latest deploy --env prod
102102
```
103103
</CodeGroup>
104104

105-
The key must belong to the target environment. Use a Production key for the default deployment, a Staging key with `--env staging`, or a key from the Preview environment with `--env preview`. A Preview deployment key can create and archive Preview branches and sync their environment variables.
105+
The key must belong to the target environment. Use a Production key with `--env prod`, a Staging key with `--env staging`, or a key from the Preview environment with `--env preview`. If you leave out `--env`, the CLI deploys to the key's environment, and a `--env` that doesn't match the key is an error. A Preview deployment key can create and archive Preview branches and sync their environment variables.
106106

107107
<Note>
108108
The deploy CLI reads environment API keys from `TRIGGER_ACCESS_TOKEN`, not

‎docs/config/extensions/prismaExtension.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ prismaExtension({
189189
"scripts": {
190190
"prebuild": "prisma generate",
191191
"dev": "trigger dev",
192-
"deploy": "trigger deploy"
192+
"deploy": "trigger deploy --env prod"
193193
}
194194
}
195195
```
@@ -331,7 +331,7 @@ steps:
331331
- name: Generate Prisma client
332332
run: npx prisma@6.19.0 generate
333333
- name: Deploy Trigger.dev
334-
run: npx trigger.dev@4.1.1 deploy
334+
run: npx trigger.dev@4.1.1 deploy --env prod
335335
env:
336336
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
337337
```
@@ -902,7 +902,7 @@ datasource db {
902902
"scripts": {
903903
"generate": "prisma generate",
904904
"dev": "pnpm generate && trigger dev",
905-
"deploy": "trigger deploy"
905+
"deploy": "trigger deploy --env prod"
906906
}
907907
}
908908
```
@@ -975,7 +975,7 @@ export default defineConfig({
975975
"scripts": {
976976
"generate": "prisma generate",
977977
"dev": "pnpm generate && trigger dev",
978-
"deploy": "trigger deploy"
978+
"deploy": "trigger deploy --env prod"
979979
}
980980
}
981981
```

‎docs/deployment/atomic-deployment.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The id is free-form and opaque to Trigger.dev — a commit SHA, a release tag, a
6060
<Step title="Deploy your tasks with an external id">
6161

6262
```bash
63-
npx trigger.dev@latest deploy --external-id "$(git rev-parse HEAD)"
63+
npx trigger.dev@latest deploy --env prod --external-id "$(git rev-parse HEAD)"
6464
```
6565

6666
</Step>
@@ -240,7 +240,7 @@ Read the commit in the place where it *is* available, and write it into both hal
240240
241241
```bash
242242
# 1. Deploy side — name the deployment after the commit.
243-
npx trigger.dev@latest deploy --external-id "$(git rev-parse HEAD)"
243+
npx trigger.dev@latest deploy --env prod --external-id "$(git rev-parse HEAD)"
244244
245245
# 2. Application side — give the running app the same value.
246246
TRIGGER_EXTERNAL_DEPLOYMENT_ID=<the-same-commit-sha>
@@ -385,7 +385,7 @@ If you filter deploys by path, derive the id from the same filter on both sides
385385
386386
```bash
387387
TASK_ID=$(git log -1 --format=%H -- trigger/)
388-
npx trigger.dev@latest deploy --external-id "$TASK_ID"
388+
npx trigger.dev@latest deploy --env prod --external-id "$TASK_ID"
389389
```
390390
391391
Compute the same value where you set your app's variable. In GitHub Actions this needs `fetch-depth: 0` on `actions/checkout` — the default shallow clone can't see far enough back.

‎docs/deployment/overview.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ To keep your app and tasks in sync without coordinating promotion at all, see [a
162162

163163
## Staging deploys
164164

165-
By default, the `deploy` command will deploy to the `prod` environment. If you want to deploy to a different environment, you can use the `--env` flag:
165+
Use the `--env` flag to choose the environment you deploy to. If you don't pass it, the `deploy` command deploys to the `prod` environment, unless `TRIGGER_ACCESS_TOKEN` holds an API key for another environment. To deploy to staging:
166166

167167
```bash
168168
npx trigger.dev deploy --env staging

‎docs/deployment/preview-branches.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Creating and deploying a preview branch manually is easy:
147147
npx trigger.dev@latest deploy --env preview
148148
```
149149

150-
This will create and deploy a preview branch, automatically detecting the git branch. If for some reason the auto-detection doesn't work it will let you know and tell you do this:
150+
This will create and deploy a preview branch, automatically detecting the git branch. When your CI checks out a detached HEAD, the branch is read from the CI provider's branch variable instead (GitLab, Bitbucket, CircleCI, Buildkite, Travis CI, Jenkins and Azure Pipelines are supported). If for some reason the auto-detection doesn't work it will let you know and tell you do this:
151151

152152
```bash
153153
npx trigger.dev@latest deploy --env preview --branch your-branch-name

‎docs/github-actions.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
env:
4848
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
4949
run: |
50-
npx trigger.dev@latest deploy --external-id ${{ github.sha }}
50+
npx trigger.dev@latest deploy --env prod --external-id ${{ github.sha }}
5151
```
5252
5353
```yaml .github/workflows/release-trigger-staging.yml
@@ -184,7 +184,7 @@ Tip: add the `trigger.dev` CLI to your `devDependencies` and the deploy command
184184
```json
185185
{
186186
"scripts": {
187-
"deploy:trigger-prod": "trigger deploy",
187+
"deploy:trigger-prod": "trigger deploy --env prod",
188188
"deploy:trigger": "trigger deploy --env staging"
189189
},
190190
"devDependencies": {
@@ -254,7 +254,7 @@ jobs:
254254
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
255255
TRIGGER_API_URL: ${{ secrets.TRIGGER_API_URL }}
256256
run: |
257-
npx trigger.dev@latest deploy
257+
npx trigger.dev@latest deploy --env prod
258258
```
259259

260260
</CodeGroup>

‎docs/manual-setup.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Then add scripts to your `package.json`:
109109
{
110110
"scripts": {
111111
"dev:trigger": "trigger dev",
112-
"deploy:trigger": "trigger deploy"
112+
"deploy:trigger": "trigger deploy --env prod"
113113
}
114114
}
115115
```

0 commit comments

Comments
 (0)