#confusion about preview environments and cli
1 messages · Page 1 of 1 (latest)
-
npx trigger.dev devand env varsThe docs say that when you add env vars in the Trigger.dev dashboard, those are the vars used by your deployed tasks. To add custom env vars to deployed tasks you must add them in the dashboard or sync them via
syncEnvVars/syncVercelEnvVars. [Deployment env vars]For the CLI, the
--env-fileoption “will only hydrate theprocess.envof the CLI process, not the tasks.” [CLI dev] This implies that task code does not automatically read from a local.envpassed to the CLI, but the docs do not explicitly state whether dev-mode tasks automatically see cloud env vars. So I can’t confidently confirm that your dev-mode tasks are using the cloud “development” environment variables; the behavior is not clearly documented. -
TRIGGER_PREVIEW_BRANCH+devTRIGGER_PREVIEW_BRANCHis documented for:- Triggering runs from your backend using the SDK (
TRIGGER_SECRET_KEY+TRIGGER_PREVIEW_BRANCH). [API keys; Preview branches] - Targeting preview branches when managing env vars via the management SDK / REST API. [Preview branch targeting]
There is no explicit documentation that
TRIGGER_PREVIEW_BRANCHaffects hownpx trigger.dev devruns tasks locally (e.g., which environment/branch’s env vars are used). So I can’t confirm that settingTRIGGER_PREVIEW_BRANCHwhile runningdevwill make your local runs use a specific preview branch’s environment. - Triggering runs from your backend using the SDK (
-
Copying env vars from
developmenttopreview
The documented ways to get env vars into Trigger.dev environments are:
- Manually add them in the dashboard. [Env vars guide]
- Bulk upload via
envvars.upload()(one-time import from a.envfile). [In your code] - Automatically sync at deploy time using
syncEnvVarsorsyncVercelEnvVars. [Deployment env vars; Sync env vars; Preview env vars]
The docs show syncEnvVars being used to pull from external services (Infisical, Vercel, etc.), not from another Trigger.dev environment. [Sync env vars; Sync from another service]
Your example:
syncEnvVars(async (ctx) => {
if (ctx.environment !== 'preview') return []
const devVars = await envvars.list(PROJECT_REF, 'dev')
return devVars.map(v => ({ name: v.name, value: v.value }))
})
This pattern (using envvars.list inside syncEnvVars to copy from dev to preview) is not described in the docs, so I can’t confirm it as a supported or recommended approach based on the available information.
What is clearly documented for preview env vars:
-
You can set env vars for the “Preview” environment (applies to all branches) and override per-branch. [Preview env vars]
- You can sync env vars into Preview using
syncEnvVars/syncVercelEnvVars, typically from an external secret store. [Preview env vars; Sync env vars]
The docs do not describe a built-in “copy from development to preview” feature beyond manually setting them or re-importing via
envvars.upload()/syncEnvVarsfrom your original source. - You can sync env vars into Preview using
-
Multiple
devprocesses + preview branches / isolationThe docs for
devmode say:npx trigger.dev devruns your task code locally; scheduling is still done in the Trigger.dev server. [How it works – dev mode]- Each task runs in a separate Node process, so long-running tasks don’t block others. [CLI dev]
However, there is no explicit documentation about:
- Running multiple
devservers from different worktrees at the same time. - How those multiple dev servers interact with the same project / environment / preview branches.
- Whether they might “overwrite” each other’s registrations or versions.
Because this behavior isn’t described, I can’t reliably confirm that two
devprocesses in different worktrees, each with its ownTRIGGER_PREVIEW_BRANCH, will be fully isolated and never interfere with each other’s tasks or registrations.
Given these gaps, for precise behavior (especially around dev-mode + preview branches + multiple worktrees), you’ll likely need to:
- Test in a throwaway project, or
- Ask the Trigger.dev team directly (e.g. GitHub Discussions / Discord), since the current docs don’t fully specify these edge cases.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@north cedar Kapa.ai is still learning and improving, please let me know how I did by reacting below.
any new updates on how we can run multiple dev servers from multiple worktrees?