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:
1url="$(vercel deploy)"2vercel alias set "$url" your-alias.app
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:
1name: Vercel Preview Deployment2env:3 VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}4 VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}5on:6 push:7 branches-ignore:8 - main9jobs:10 Deploy-Preview:11 runs-on: ubuntu-latest12 steps:13 - uses: actions/checkout@v214 - name: Install Vercel CLI15 run: npm install --global vercel@latest16 - name: Pull Vercel Environment Information17 run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}18 - name: Build Project Artifacts19 run: vercel build --token=${{ secrets.VERCEL_TOKEN }}20 - name: Deploy Project Artifacts to Vercel21 run: |22 url="$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})"23 vercel alias --token=${{ secrets.VERCEL_TOKEN }} set "$url" your-alias.app