#confusion about preview environments and cli

1 messages · Page 1 of 1 (latest)

fresh cairnBOT
#

Hi @north cedar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

  1. npx trigger.dev dev and env vars

    The 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-file option “will only hydrate the process.env of the CLI process, not the tasks.” [CLI dev] This implies that task code does not automatically read from a local .env passed 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.

  2. TRIGGER_PREVIEW_BRANCH + dev

    TRIGGER_PREVIEW_BRANCH is documented for:

    There is no explicit documentation that TRIGGER_PREVIEW_BRANCH affects how npx trigger.dev dev runs tasks locally (e.g., which environment/branch’s env vars are used). So I can’t confirm that setting TRIGGER_PREVIEW_BRANCH while running dev will make your local runs use a specific preview branch’s environment.

  3. Copying env vars from development to preview

#

The documented ways to get env vars into Trigger.dev environments are:

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() / syncEnvVars from your original source.

  1. Multiple dev processes + preview branches / isolation

    The docs for dev mode say:

    • npx trigger.dev dev runs 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 dev servers 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 dev processes in different worktrees, each with its own TRIGGER_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.

woeful lake
#

any new updates on how we can run multiple dev servers from multiple worktrees?