Home > front end >  NX Monorepo Next.js project deployment via Gitlab CI to Vercel
NX Monorepo Next.js project deployment via Gitlab CI to Vercel

Time:02-10

I am trying do deploy a NX Monorepo Next.js project via Gitlab CI to Vercel. Here is .yml file.

image: node:lts
stages:
  - build
  - web-test
  - deploy
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules/
build website:
  stage: build
  script:
    - npm install
    - npm i @nrwl/cli -g
    - nx run shop-wine:build
  artifacts:
    paths:
      - ./dist
test website:
  stage: web-test
  script:
    - npm install
    - npm i @nrwl/cli -g
    - nx run shop-wine:serve &
    - sleep 60
    - curl "http://localhost:4200" | grep -q "Welcome shop-wine"
deploy-to-vercel:
  stage: deploy

  variables:
    PREVIEW_URL: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG.$VERCEL_USER.vercel.app
    VERCEL_ORG_ID: $VERCEL_ORG_ID
    VERCEL_PROJECT_ID: $VERCEL_PROJECT_ID

  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == 'main'

  environment:
    name: vercel/$CI_COMMIT_REF_NAME
    url: https://$PREVIEW_URL

  script:
    - npm i -g vercel
    - DEPLOYMENT_URL=$(VERCEL_ORG_ID=$VERCEL_ORG_ID VERCEL_PROJECT_ID=$VERCEL_PROJECT_ID vercel --confirm -t $VERCEL_TOKEN --scope $VERCEL_USER)
    - vercel alias set $DEPLOYMENT_URL $PREVIEW_URL -t $VERCEL_TOKEN --scope $VERCEL_USER 

There are no problems with build and web-test stages but when I get to manual deploy-to-vercel stage I am getting the following error from GitLab: enter image description here

Here are the overrides on Vercel: enter image description here

I am also using a plugin to automaticaly deploy to Vercel. As you can see it is deployed with success ahead of build test and manual deploy-to vercel stages. enter image description here

But when it gets to manual deploy-to-vercel here is Vercel error. Let me know if I am doing something wrong. enter image description here enter image description here

CodePudding user response:

  •  Tags:  
  • Related