How do I set up a staging environment on Vercel?

Vercel allows you to collaborate seamlessly with your team by providing Preview Deployments for every commit made to your project. In addition to this, you can provide Environment Variables specific to the Preview Environment, ensuring different variables are used for Preview and Production Deployments. Furthermore, it is possible to specify different Environment Variables for a specific Preview branch.

In some cases, it can be beneficial to use a staging environment to test your latest changes before pushing to Production. This article covers the steps required to set up a staging environment.

Adding a Staging Domain

To create a staging environment, you'll first need to add a custom domain to your project.

You can add a domain by clicking the "Settings" tab from a Project and selecting the Domains section. From the Domains section, you can assign a domain to the appropriate Git branch.

WARNING: When adding a domain, it is first automatically assigned to your default branch. Make sure to click the "Edit" button and assign it to the appropriate Git branch.
Adding a staging domain to the staging branch through a Project's Domain settings.
Adding a staging domain to the staging branch through a Project's Domain settings.

Adding Environment Variables

Using the Environment Variables UI, which is available by selecting the Environment Variables tab in a Project's settings, we can add a Preview Environment Variable to the appropriate Git branch.

Any branch-specific variables will override other variables with the same name. This means you don't need to replicate all your existing Preview variables for each branch – you only need to add the values you wish to override.

Adding an Environment Variable to the staging branch.
Adding an Environment Variable to the staging branch.

After adding all the necessary Environment Variables for your staging environment, make sure to redeploy your latest staging Preview Deployment to apply the Environment Variables.

Redeploying a Deployment from the Deployment overview.
Redeploying a Deployment from the Deployment overview.

Couldn't find the guide you need?