Try   HackMD

Vercel - Environment Variables and CLI (vercel env)

Get Started

Vercel is an end-to-end platform for developers, that allows you to create and deploy your web application. Vercel provides the following features to enable you to serve fast and personalized content to your users:

  • Deployments
  • CI/CD
  • Custom domains
  • Monitoring your project

CLI

vercel env

The vercel env command is used to manage Environment Variables of a Project, providing functionality to list, add, remove, and export.

vercel env ls [environment] : Using the vercel env command to list Environment Variables for a specific Environment in a Vercel Project.

Example usage of getting environment variables of project

Download and install vercel CLI

Run commands:

npm i -g vercel
npm i -g vercel@latest
vercel --version

Login to vercel

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Setup scope and link to the existing project. When seeing Error: EPERM: operation not permitted, mkdir 'C:\WINDOWS\System32.vercel':

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Solution:
This error occurs because the current working directory of the PC is not in the project. Make sure you clone the project from github locally and cd to the project before running the command vercel.

Successfully set up:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

List all current environment variables

Run commands vercel env ls [environment], for example, to list all preview environments:

vercel env ls preview

Get vercel environment variable for a certain branch

Source
https://github.com/vercel/vercel/pull/9028
https://github.com/vercel/vercel/releases/tag/vercel%4028.9.0

Update the vercel version to the version (or higher) that supports the feature

npm i -g vercel@28.9.0

Pull all environment variables of preview environment on main branch, vercel will create a file .vercel/.env.preview.local and store these variables into the file automatically

vc pull --branch main --environment preview

Access vercel features of an account without login

  • Use access token that is set on the vercel account. Create a token with a proper access scope and expired date, and save the token.

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  • Open a terminal that has vercel installed, no need to log in vercel (to make sure the token works, should logout vercel if the current status is login)

  • Add --token [the vercel access token] behind the command to give the right permission for the vercel command, for example:

vc pull --git-branch main --environment preview --token L2UKvAes45DDTBLBtdZJtbPM
  • Will be able to access the vercel account successfully and see the command execution results
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

Specify scope

When the current account is a member of a team on vercel, might need to provide the right scope to access the certain resource:

vc --scope myTeam pull --git-branch main --environment preview --token L2UKvAes45DDTBLBtdZJtbPM --yes
tags: devops cicd vercel