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:
Then link your Vercel application codebase locally by changing into the root directory of your application, then running:
Next, create the environment variables in JSON for a single environment (e.g.Development):
In your terminal, define which environment you'll be importing to:
Then run:
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:
Then simply repeat for other environments!
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.
Trusted by the world’s best DevOps and security teams. Doppler is the secrets manager developers love.