Deployment via Gitlab CI to dev domain

Hello together,
I currently have the problem that I don’t understand what I need to write in .gitlab-ci.yml so that I can make a deployment AND then link the dev domain. My goal is to have a preview environment on a specific domain.

Automatic Vercel deployment via Gitlab hooks are turned off.

I’ve spent hours researching and trying here, but can’t find a good solution.

This is what important parts of my .gitlab-ci.yml look like:

.project deploy:
    stage: deploy
    image: node:18
    before_script:
        # Prepare env vars
        - export VERCEL_PROJECT_ID=$VERCEL_STYLEGUIDE_PROJECT_ID
        # Install Vercel CLI
        - npm install --global vercel
        # Go to frontend directory
        - cd apps/frontend

project_deploy_dev:
    extends: .project_deploy
    environment:
        name: dev
    script:
        # Deploy to Vercel
        - vercel pull --yes --environment=preview --token=$VERCEL_TOKEN
        - vercel deploy --token=$VERCEL_TOKEN
    rules:
        - if: '$CI_COMMIT_BRANCH == "develop"'
          when: manual

project_deploy_prod:
    extends: .project_deploy
    environment:
        name: prod
    script:
        # Deploy to Vercel
        - vercel pull --yes --environment=production --token=$VERCEL_TOKEN
        - vercel deploy --prod --token=$VERCEL_TOKEN
    rules:
        - if: '$CI_COMMIT_BRANCH == "main"'
          when: manual

Deployments to the prod env are no problem and work so far (with correct domain)

Thank you in advance!

Hey @alexba! If the rest of the script is working how you like, I would just add a vercel alias line after vercel deploy to apply your custom dev domain.

You can get the deployment URL from the deploy command using one of the methods suggested here: shell - How to assign the output of a Bash command to a variable? - Stack Overflow

@amyegan Thank you for your answer!

I have tried something similar (although I haven’t mentioned it yet):

project_deploy_dev:
    extends: .project_deploy
    environment:
        name: dev
    script:
        # Deploy to Vercel
        - vercel pull --yes --environment=preview --token=$VERCEL_TOKEN
        - DEPLOYMENT_URL=$(vercel deploy --token=$VERCEL_TOKEN)
        - vercel alias set $DEPLOYMENT_URL domain1.com --token=$VERCEL_TOKEN --scope=$VERCEL_ORG_ID
        - vercel alias set $DEPLOYMENT_URL domain2.com --token=$VERCEL_TOKEN --scope=$VERCEL_ORG_ID
    rules:
        - if: '$CI_COMMIT_BRANCH == "develop"'
          when: manual

However, I’m getting the following error:

Vercel CLI 36.0.0
> Assigning alias domain1.com to deployment shop-af3mwp9nv-i-example.vercel.app
Fetching domain domain1.com under example
Error: You don't have access to the domain domain1.com under example.

I should have access to the domain. It’s already linked.

Were domain1.com and domain2.com already added in Project Settings?

Yes, it’s already listed there (see the first screenshot) :slight_smile:

I have a couple of things for you to try.

Check the owner of the domains. If they currently belong to your personal account, move them so that the team owns the domains instead. Then give your workflow a try.

If that doesn’t work then I have one more thing to try. You may have already tried this next idea, but typos are a common issue so I always like to suggest checking this when something looks like it should work but doesn’t. Copy the domain from your project settings and past it as your DEPLOYMENT_URL value to make sure it’s exactly the same. Then give your workflow another try.

Please let me know whether either of those tricks gets it working for you. :pray:

@amyegan Thank you for your answer.

The domain already belongs to another Vercel account and we want to set up a subdomain for a client project.

Example:

  • domain.com belongs to Vercel account 1 and cannot be changed
  • sub.domain.com must run on Vercel account 2 for various reasons. I was invited to Vercel account 2 and I’m not the owner.

Thanks for waiting. Having the domain owned by a different team explains the error message. If you’re using the team 2 scope to deploy, then it wouldn’t have access to control a domain owned by team 1.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.