Dynamically create env variables in mono repos using vercel github bot

There are lots of cases when in mono-repo you create a pull request that changes two or more projects. Lets consider a simple example, a monorepo with backend and frontend.
Both of these projects create a deployment to vercel (preview) on each pull request.
So lets say you are creating a pull request from branch feature-1 to main:
1- front: deployed to vercel preview on url: something-feat-1-preview.vercel.app
2- back: deplyoyed to vercel preview on url: something-feat1-be-preview.vercel.app

The front-end uses the backend URL to make requests to, but on each deplyoment these URLS change and we need a way to set it to the correct thing (also there are cases where the build process uses the API_URL, so the project might get built with the incorrect url, frontend’s deployment should happen AFTER the backend project is deployed). I really don’t know how to achieve this. I would appreacite any help!! thanks for your time >_<

Hi @fohoov! You could use the vercel alias command in the CLI to assign consistent domains to each new preview deployment of the frontend and backend projects. A custom workflow could work well for this if you want to automate.

As another option, you could take advantage of the predictable URL with Git branch and branch-specific preview environment variables.

There’s also a new option to automatically skip unnecessary deployments in monorepos which could help you avoid unnecessary deployments.

1 Like

Thanks for your reply! It really helped me a lot! I used the cli to build and deploy. The only downside is that I have to do two things:

  1. disable automatic build/deploys on any branch other than main
  2. the lovely vercel bot doesn’t show the deployed URLs after I deploy using vercel deploy anymore (cuz of step-1)

Is there a way to notify the vercel-bot that: “hey, I did this manually can you please update your comments and URLs?”

I don’t have a way to tell the vercel-bot to add a comment if it didn’t create the deployment, but you could add a PR comment as part of a custom workflow.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.