| title | Sync env vars |
|---|---|
| sidebarTitle | syncEnvVars |
| description | Use the syncEnvVars build extension to automatically sync environment variables to Trigger.dev |
The syncEnvVars build extension will sync env vars from another service into Trigger.dev before the deployment starts. This is useful if you are using a secret store service like Infisical or AWS Secrets Manager to store your secrets.
syncEnvVars takes an async callback function, and any env vars returned from the callback will be synced to Trigger.dev.
import { defineConfig } from "@trigger.dev/sdk";
import { syncEnvVars } from "@trigger.dev/build/extensions/core";
export default defineConfig({
build: {
extensions: [
syncEnvVars(async (ctx) => {
return [
{ name: "SECRET_KEY", value: "secret-value" },
{ name: "ANOTHER_SECRET", value: "another-secret-value" },
];
}),
],
},
});The callback is passed a context object with the following properties:
environment: The environment name that the task is being deployed to (e.g.production,staging, etc.)projectRef: The project ref of the Trigger.dev projectenv: The environment variables that are currently set in the Trigger.dev project
In this example we're using env vars from Infisical.
import { defineConfig } from "@trigger.dev/sdk";
import { syncEnvVars } from "@trigger.dev/build/extensions/core";
import { InfisicalSDK } from "@infisical/sdk";
export default defineConfig({
build: {
extensions: [
syncEnvVars(async (ctx) => {
const client = new InfisicalSDK();
await client.auth().universalAuth.login({
clientId: process.env.INFISICAL_CLIENT_ID!,
clientSecret: process.env.INFISICAL_CLIENT_SECRET!,
});
const { secrets } = await client.secrets().listSecrets({
environment: ctx.environment,
projectId: process.env.INFISICAL_PROJECT_ID!,
});
return secrets.map((secret) => ({
name: secret.secretKey,
value: secret.secretValue,
}));
}),
],
},
});The syncVercelEnvVars build extension syncs environment variables from your Vercel project to Trigger.dev.
You can find / generate the VERCEL_ACCESS_TOKEN in your Vercel
dashboard. Make sure the scope of the token covers
the project with the environment variables you want to sync.
The API is still used to determine which environment variables are configured for your project, but
the actual values come from the local environment. Reading values from process.env allows the
extension to use values that Vercel integrations (such as the Neon integration) set per preview
deployment in the "Provisioning Integrations" phase that happens just before the Vercel build
starts.
This ensures that the correct database connection strings are used for your
selected environment and current branch, as syncVercelEnvVars may not accurately reflect
branch-specific database credentials when run locally.
import { defineConfig } from "@trigger.dev/sdk";
import { syncVercelEnvVars } from "@trigger.dev/build/extensions/core";
export default defineConfig({
project: "<project ref>",
// Your other config settings...
build: {
// This will automatically use the VERCEL_ACCESS_TOKEN and VERCEL_PROJECT_ID environment variables
extensions: [syncVercelEnvVars()],
},
});Or you can pass in the token and project ID as arguments:
import { defineConfig } from "@trigger.dev/sdk";
import { syncVercelEnvVars } from "@trigger.dev/build/extensions/core";
export default defineConfig({
project: "<project ref>",
// Your other config settings...
build: {
extensions: [
syncVercelEnvVars({
projectId: "your-vercel-project-id",
vercelAccessToken: "your-vercel-access-token", // optional, we recommend to keep it as env variable
vercelTeamId: "your-vercel-team-id", // optional
}),
],
},
});The syncNeonEnvVars build extension syncs environment variables from your Neon database project to Trigger.dev. It automatically detects branches and builds the appropriate database connection strings for your environment.
You can generate a NEON_ACCESS_TOKEN in your Neon dashboard.
This is because Neon's Vercel integration already handles environment variable synchronization in Vercel environments.
If you have the Neon database Vercel integration installed and are running builds outside of the Vercel environment, we recommend using `syncNeonEnvVars` in addition to `syncVercelEnvVars` for your database environment variables.This ensures that the correct database connection strings are used for your selected environment and current branch, as syncVercelEnvVars may not accurately reflect branch-specific database credentials when run locally.
import { defineConfig } from "@trigger.dev/sdk";
import { syncNeonEnvVars } from "@trigger.dev/build/extensions/core";
export default defineConfig({
project: "<project ref>",
// Your other config settings...
build: {
// This will automatically use the NEON_ACCESS_TOKEN and NEON_PROJECT_ID environment variables
extensions: [syncNeonEnvVars()],
},
});Or you can pass in the token and project ID as arguments:
import { defineConfig } from "@trigger.dev/sdk";
import { syncNeonEnvVars } from "@trigger.dev/build/extensions/core";
export default defineConfig({
project: "<project ref>",
// Your other config settings...
build: {
extensions: [
syncNeonEnvVars({
projectId: "your-neon-project-id",
neonAccessToken: "your-neon-access-token", // optional, we recommend to keep it as env variable
branch: "your-branch-name", // optional, defaults to ctx.branch
databaseName: "your-database-name", // optional, defaults to the first database
roleName: "your-role-name", // optional, defaults to the database owner
envVarPrefix: "MY_PREFIX_", // optional, prefix for all synced env vars
}),
],
},
});The extension syncs the following environment variables (with optional prefix):
DATABASE_URL- Pooled connection stringDATABASE_URL_UNPOOLED- Direct connection stringPOSTGRES_URL,POSTGRES_URL_NO_SSL,POSTGRES_URL_NON_POOLINGPOSTGRES_PRISMA_URL- Connection string optimized for PrismaPOSTGRES_HOST,POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DATABASEPGHOST,PGHOST_UNPOOLED,PGUSER,PGPASSWORD,PGDATABASE