Skip to content

Commit c322926

Browse files
committed
Add a better explanation and details about env vars
1 parent 7c59347 commit c322926

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

docs/deployment/preview-branches.mdx

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";
77

88
<UpgradeToV4Note />
99

10-
## How does it work?
10+
## How to use preview branches
1111

12-
The Preview environment is special – you create branches from it. We recommend you automatically create a preview branch for each git branch when a Pull Request is opened and then archive it automatically when the PR is merged/closed.
12+
The preview environment is special – you create branches from it. The branches you create live under the preview environment and have all the features you're used to from other environments (like staging or production). That means you can trigger runs, have schedules, test them, use Realtime, etc.
13+
14+
![Preview environment and branches](/deployment/preview-environment-branches.png)
15+
16+
We recommend you automatically create a preview branch for each git branch when a Pull Request is opened and then archive it automatically when the PR is merged/closed.
1317

1418
The process to use preview branches looks like this:
1519

@@ -25,7 +29,7 @@ There are two main ways to do this:
2529

2630
### Limits on active preview branches
2731

28-
We restrict the number of active preview branches (per project). You can archive a preview branch at any time (automatically or manually) to unlock another slot.
32+
We restrict the number of active preview branches (per project). You can archive a preview branch at any time (automatically or manually) to unlock another slot – or you can upgrade your plan.
2933

3034
Once archived you can still view the dashboard for the branch but you can't trigger or execute runs (or other write operations).
3135

@@ -145,3 +149,55 @@ From the "Preview branches" page you can create a branch:
145149
You can also archive a branch:
146150

147151
![Archive preview branch](/deployment/preview-branches-archive.png)
152+
153+
## Environment variables
154+
155+
You can set environment variables for "Preview" and they will get applied to all branches (existing and new). You can also set environment variables for a specific branch. If they are set for both then the branch-specific variables will take precedence.
156+
157+
![Environment variables](/deployment/preview-environment-variables.png)
158+
159+
These can be set manually in the dashboard, or automatically at deploy time using the [syncEnvVars()](/config/extensions/syncEnvVars) or [syncVercelEnvVars()](/config/extensions/syncEnvVars#syncvercelenvvars) build extensions.
160+
161+
### Sync environment variables
162+
163+
You can find this in the Trigger.dev dashboard. Full instructions are in the [syncEnvVars()](/config/extensions/syncEnvVars) documentation.
164+
165+
```ts trigger.config.ts
166+
import { defineConfig } from "@trigger.dev/sdk";
167+
// You will need to install the @trigger.dev/build package
168+
import { syncEnvVars } from "@trigger.dev/build/extensions/core";
169+
170+
export default defineConfig({
171+
//... other config
172+
build: {
173+
// This will automatically detect and sync environment variables
174+
extensions: [
175+
syncEnvVars(async (ctx) => {
176+
// You can fetch env variables from a 3rd party service like Infisical, Hashicorp Vault, etc.
177+
// The ctx.branch will be set if it's a preview deployment.
178+
return await fetchEnvVars(ctx.environment, ctx.branch);
179+
}),
180+
],
181+
},
182+
});
183+
```
184+
185+
### Sync Vercel environment variables
186+
187+
You need to set the `VERCEL_ACCESS_TOKEN`, `VERCEL_PROJECT_ID` and `VERCEL_TEAM_ID` environment variables. You can find these in the Vercel dashboard. Full instructions are in the [syncVercelEnvVars()](/config/extensions/syncEnvVars#syncvercelenvvars) documentation.
188+
189+
The extension will automatically detect a preview branch deploy from Vercel and sync the appropriate environment variables.
190+
191+
```ts trigger.config.ts
192+
import { defineConfig } from "@trigger.dev/sdk";
193+
// You will need to install the @trigger.dev/build package
194+
import { syncVercelEnvVars } from "@trigger.dev/build/extensions/core";
195+
196+
export default defineConfig({
197+
//... other config
198+
build: {
199+
// This will automatically detect and sync environment variables
200+
extensions: [syncVercelEnvVars()],
201+
},
202+
});
203+
```
18.8 KB
Loading
Loading

0 commit comments

Comments
 (0)