Skip to content

How to alias a preview deployment using the CLI

You can use Vercel CLI to create Preview Deployments and can also use the Vercel CLI to alias a URL to that deployment. Each preview deployment has a unique URL. The latest Preview Deployment is automatically aliased to a URL, ensuring you'll have a stable URL pointing to the last Preview Deployment.

This covers adding another URL to the Deployment using the alias command. In this example we use the Vercel CLI to do a deployment using the vercel deploy command. A successful deployment writes the deployed URL to the Standard Output so you can use it in later commands.

As an example:

vercel deploy > domain.txt
vercel alias -set `cat domain.txt`

Bash to deploy and then alias a URL to that Preview Deployment.

Example with GitHub Actions

In this article we cover how to deploy using GitHub Actions. We can expand that example and alter the last couple of lines to do that auto-aliasing.

To set this Action up, please refer back to the original article. Then change the last lines as below:

name: Vercel Preview Deployment
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
      - main
    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
      - name: Install Vercel CLI
        run: npm install --global vercel@latest
      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy Project Artifacts to Vercel
        run: |
          vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > domain.txt
          vercel alias --token=${{ secrets.VERCEL_TOKEN }} set `cat domain.txt`

A GitHub Action to create a Vercel Preview Deployment and Alias a URL to it.

Couldn't find the guide you need?