Tutorials
1 min read

How to import multiple environment variables to Vercel

Bulk import environment variables to a Vercel environment with a single CLI command.

Mar 23, 2022
Ryan Blunden Avatar
Ryan Blunden
Senior Developer Advocate
How to import multiple environment variables to Vercel
Back to the blog
How to import multiple environment variables to Vercel
Share
Tutorials

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:

1brew install jq
2npm i -g vercel

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

1vercel link

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

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

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

1VERCEL_ENV="development"

Then run:

1source <(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:

1unlink 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.

Stay up to date with new platform releases and get to know the team of experts behind them.

Related Content

Explore More