Deploy and Test Local Feature Branches Like a Pro with Vercel CLI - XM Cloud and Vercel
Hello everyone! In this blog, we'll explore how to use the Vercel CLI to deploy local branch changes to a Vercel Preview environment for quick verification and validation.
Ideally, we have a proper CI/CD pipeline in place to build and deploy changes to the appropriate Vercel environment. However, there are situations—such as urgent bug fixes—where you might need to quickly validate your changes without waiting for the full pipeline. In such cases, you can use the Vercel CLI to deploy your local changes directly, typically to a Preview environment. Even if something goes wrong, Vercel makes it easy to roll back: you can simply redeploy a previous build from the dashboard and restore the environment within minutes
Let's begin by setting up the Vercel CLI on your local machine. At this point, you should have already created a branch from your main or develop branch and pulled the latest commits. You've made your changes and tested them locally — now you're ready to deploy them to Vercel. A project is already setup in vercel as we will be requring the organization id and project id to connect our local repository for build and deploy.
Install Vercel Cli: We will install the cli globally.
npm i -g vercel@latest
To get organization id you can navigate to Vercel dashboard -->select your Organization --> Settings --> General --> Team Id
To get project id you can navigate to Vercel dashboard -->select your Project --> Settings --> General --> Project Id
In our case, My repository is using Bitbucket for build and deployment. I will authenticate using bitbucket login.
Navigate to the root folder of your project and run the following command. If you're working with a single frontend application, this should be your project’s root. However, if you have multiple frontend applications, make sure you navigate to the specific application's root folder that you want to deploy to the corresponding project in Vercel.
vercel login
This will ask you to select an authentication provider. In my case, I selected Bitbucket and once the authentication is done, you will find .vercel folder in your current repository with project.json file. This will include your priject id and organization id. Verify if it is exactly same to make sure the linking of your local branch is properly setup to vercel project.
Now its time for our local branch build and deployment. Run the below command
vercel
You will be ask few things before actually the build and deployment is pushed to vercel. Select the appropriate options. Once done , you can navigate to vercel project dashboard and can see the build is triggered and deployment is taking place.
Once deployment is successful, you can preview the changes now by browsing.
Happy Learning!!
You can check my other blogs too if interested. Blog Website
Comments
Post a Comment