0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Batch to add / remove environment variables by Vercel CLI

Posted at

Not sure why Vercel CLI 28.9.0 has no way to import whole .env file or all environment variables in one project or environment. Write a simple bash script to achieve it:

(Tested on macOS zsh)

Check current environment variables and backup

# List up all current environment variables
vercel env ls

# Backup
vercel env pull .env.production.bak --environment production
vercel env pull .env.development.bak --environment development
vercel env pull .env.preview.bak --environment preview

Add environment variables

cat .env.production | sed 's/=/ /' | xargs -n 2 bash -c 'echo -n $1 | vercel env add $0 production'
cat .env.staging | sed 's/=/ /' | xargs -n 2 bash -c 'echo -n $1 | vercel env add $0 development'
cat .env.staging | sed 's/=/ /' | xargs -n 2 bash -c 'echo -n $1 | vercel env add $0 preview'

Remove all Vercel environment variables

vercel env ls | sed 's/=/ /' | awk 'NR>2 {print $1, $3}' | xargs -n 2 bash -c 'vercel env rm $0 ${1,,} -y'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?