vercel deploy
Learn how to deploy your Vercel projects using the vercel deploy CLI command.The vercel deploy
command deploys Vercel projects, executable from the project's root directory or by specifying a path. You can omit 'deploy' in vercel deploy
, as vercel
is the only command that operates without a subcommand. This document will use 'vercel' to refer to vercel deploy
.
vercel
vercel --cwd [path-to-project]
vercel deploy --prebuilt
When deploying, stdout
is always the Deployment URL.
vercel > deployment-url.txt
In the following example, you create a bash script that you include in your CI/CD workflow. The goal is to have all preview deployments be aliased to a custom domain so that developers can bookmark the preview deployment URL. Note that you may need to define the scope when using vercel alias
# save stdout and stderr to files
vercel deploy >deployment-url.txt 2>error.txt
# check the exit code
code=$?
if [ $code -eq 0 ]; then
# Now you can use the deployment url from stdout for the next step of your workflow
deploymentUrl=`cat deployment-url.txt`
vercel alias $deploymentUrl my-custom-domain.com
else
# Handle the error
errorMessage=`cat error.txt`
echo "There was an error: $errorMessage"
fi
If you need to check for errors when the command is executed such as in a CI/CD workflow,
use stderr
. If the exit code is anything other than 0
, an error has occurred. The
following example demonstrates a script that checks if the exit code is not equal to 0:
# save stdout and stderr to files
vercel deploy >deployment-url.txt 2>error.txt
# check the exit code
code=$?
if [ $code -eq 0 ]; then
# Now you can use the deployment url from stdout for the next step of your workflow
deploymentUrl=`cat deployment-url.txt`
echo $deploymentUrl
else
# Handle the error
errorMessage=`cat error.txt`
echo "There was an error: $errorMessage"
fi
These are options that only apply to the vercel
command.
The --prebuilt
option can be used to upload and deploy the results of a previous vc build
execution located in the .vercel/output directory. See vercel build and Build Output API for more details.
vercel --prebuilt
You should also consider using the archive option to minimize the number of files uploaded and avoid hitting upload limits:
# Build the project locally
vercel build
# Deploy the pre-built project, archiving it as a .tgz file
vercel deploy --prebuilt --archive=tgz-split
This example uses the vercel build
command to build your project locally. It then uses the --prebuilt
and --archive=tgz-split
options on the deploy
command to compress the build output and then deploy it.
The --build-env
option, shorthand -b
, can be used to provide environment variables to the build step.
vercel --build-env KEY1=value1 --build-env KEY2=value2
The --yes
option can be used to skip questions you are asked when setting up a new Vercel project.
The questions will be answered with the provided defaults, inferred from vercel.json
and the folder name.
vercel --yes
The --env
option, shorthand -e
, can be used to provide environment variables at runtime.
vercel --env KEY1=value1 --env KEY2=value2
The --name
option has been deprecated in favor of
Vercel project linking, which allows you to link
a Vercel project to your local codebase when you run
vercel
.
The --name
option, shorthand -n
, can be used to provide a Vercel project name for a deployment.
vercel --name foo
The --prod
option can be used to create a deployment for a production domain specified in the Vercel project dashboard.
vercel --prod
This CLI option will override the Auto-assign Custom Production Domains project setting.
Must be used with --prod
. The --skip-domain
option will disable the automatic promotion (aliasing) of the relevant domains to a new production deployment. You can use vercel promote
to complete the domain-assignment process later.
vercel --prod --skip-domain
The --public
option can be used to ensures the source code is publicly available at the /_src
path.
vercel --public
The --regions
option can be used to specify which regions the deployments Serverless Functions should run in.
vercel --regions sfo1
The --no-wait
option does not wait for a deployment to finish before exiting from the deploy
command.
vercel --no-wait
The --force
option, shorthand -f
, is used to force a new deployment without the build cache.
vercel --force
The --with-cache
option is used to retain the build cache when using --force
.
vercel --force --with-cache
The --archive
option compresses the deployment code into one or more files before uploading it. This option should be used when deployments include thousands of files to avoid rate limits such as the files limit.
In some cases, --archive
makes deployments slower. This happens because the caching of source files to optimize file uploads in future deployments is negated when source files are archived.
vercel deploy --archive=tgz
The beta format tgz-split
improves upon tgz
by splitting large archives into smaller parts. This makes uploads faster and helps avoid file size limits.
vercel deploy --archive=tgz-split
The --logs
option, shorthand -l
, also prints the build logs.
vercel deploy --logs
The --meta
option, shorthand -m
, is used to add metadata to the deployment.
vercel deploy --meta KEY1=value1
Deployments can be filtered using this data with vercel list --meta
.
Use the --target
option to define the environment you want to deploy to. This could be production, preview, or a custom environment. For more information, see Using an environment through the Vercel CLI.
vercel deploy --target=staging
The following global options can be passed when using the vercel deploy
command:
For more information on global options and their usage, refer to the options section.
Was this helpful?