How to import multiple environment variables to Vercel

Bulk import environment variables to a Vercel environment with a single CLI command.
Mar 24, 2022

Vercel's dashboard or CLI doesn't yet provide a solution for bulk uploading or adding multiple environment variables, but with the bash shell, jq, and Vercel CLI, we can make it happen!

It works by defining the environment variables in JSON format and using jq to transform the JSON into a vercel env add commands.

Install jq and the Vercel CLI:

brew install jq
npm i -g vercel

Then link your Vercel application codebase locally by changing into the root directory of your application, then running:

vercel link

Next, create the environment variables in JSON for a single environment (e.g.Development):

// vercel-dev-env-vars.json
  "API_SECRET": "d3f5c0a1-2aaf-4e01-b94c-a9a8071896a6",
  "AUTH_TOKEN": "eeb40e34-a9e5-4781-88ef-3a9a63fc3f27"

In your terminal, define which environment you'll be importing to:


Then run:

source <(jq -rj '. | to_entries[] | "echo -n \"\(.value)\" | vercel env add \(.key) $VERCEL_ENV;\n"' vercel-dev-env-vars.json)

You'll see the sequential output from the Vercel CLI as each variable is added successfully.

Then delete the JSON environment variables file so any sensitive data is not left sitting unencrypted on your machine:

unlink vercel-dev-env-vars.json

Then simply repeat for other environments!

Shameless plug

If you're reading this post, you clearly care about automation when it comes to managing application secrets and configuration.

As a Developer Advocate from Doppler, I'm a bit biased, but that's where the Doppler CLI and Doppler Vercel Integration can help with secret automation features such as a Git-style activity log with instant rollback support, automatic production redeploys when secrets change, and more.