Skip to content

Commit 71ce3bf

Browse files
committed
Adds an entry for targetting preview branches
1 parent 9a74576 commit 71ce3bf

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/management/authentication.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,44 @@ await envvars.upload("proj_1234", "dev", {
9494
},
9595
override: true,
9696
});
97+
```
98+
99+
### Preview branch targeting
100+
101+
When working with preview branches, you may need to target a specific branch when making API calls. This is particularly useful for managing environment variables or other resources that are scoped to individual preview branches.
102+
103+
To target a specific preview branch, include the `x-trigger-branch` header in your API requests with the branch name as the value:
104+
105+
```bash
106+
curl --request PUT \
107+
--url https://api.trigger.dev/api/v1/projects/{projectRef}/envvars/preview/DATABASE_URL \
108+
--header 'Authorization: Bearer <token>' \
109+
--header 'x-trigger-branch: feature-xyz' \
110+
--header 'Content-Type: application/json' \
111+
--data '{
112+
"value": "your_preview_database_url"
113+
}'
114+
```
115+
116+
This will set the `DATABASE_URL` environment variable specifically for the `feature-xyz` preview branch.
117+
118+
<Note>
119+
The `x-trigger-branch` header is only relevant when working with the `preview` environment (`{env}` parameter set to `preview`). It has no effect when working with `dev`, `staging`, or `prod` environments.
120+
</Note>
121+
122+
#### SDK usage with preview branches
123+
124+
When using the SDK to manage preview branch environment variables, the branch targeting is handled automatically when you're running in a preview environment with the `TRIGGER_PREVIEW_BRANCH` environment variable set. However, you can also specify the branch explicitly:
125+
126+
```ts
127+
import { configure, envvars } from "@trigger.dev/sdk";
128+
129+
configure({
130+
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
131+
previewBranch: "feature-xyz", // Optional: specify the branch
132+
});
133+
134+
await envvars.update("proj_1234", "preview", "DATABASE_URL", {
135+
value: "your_preview_database_url",
136+
});
97137
```

0 commit comments

Comments
 (0)