serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

Can't pass env variables in gitlab environment to serverless

Open agnese-kerubina opened this issue 6 years ago • 3 comments

Describe the bug

I'm trying to wrap up serverless deployment of Next.js, however I can't get Gitlab env variables to work and get accepted by serverless. It accepts aws key and id fine, just none of the custom ones get taken into account.

Screenshots/Code/Logs

Here is my serverless.yml

myNextApplication:
  component: "./node_modules/@sls-next/serverless-component"
  inputs:
    domain: ${env.DOMAIN}
    name: ${env.APP_NAME}
    bucketName: ${env.APP_NAME}
    bucketRegion: ${env.AWS_BUCKET_REGION}
}

And my super simple .gitlab-ci.yml

stages:
  - deploy

deploy:
  stage: deploy
  image: node
  before_script:
    - npm config set prefix /usr/local
    - npm install -g serverless
    - npm install
  script:
    - >-
      AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
      APP_NAME=$APP_NAME
      NODE_ENV=$NODE_ENV
      DOMAIN=$DOMAIN
      AWS_BUCKET_REGION=$AWS_BUCKET_REGION
      serverless

Versions

  • OS/Environment: Gitlab-CI runner
  • @sls-next/serverless-component version: 1.18.0
  • Next.js version: n/a

agnese-kerubina avatar Nov 13 '20 23:11 agnese-kerubina

My apologies, it was issue on gitlab end.

agnese-kerubina avatar Nov 14 '20 00:11 agnese-kerubina

@Reiiya Hi. Hm, How did you solve this? I tried different things and seems can only pass single variable with single line: 🤷‍♂️

NODE_ENV='production'  serverless

maxim-c avatar Dec 14 '20 12:12 maxim-c

Hey @maxim-c . It was a dumb error on my end.

I set environment variables via gitlab global variables but branch I tried to deploy on didn't have access to them.

I changed my .gitlab-ci.yml too. I don't pass any variables to serverless call at all, they just worked from gitlab globals in my case.

agnese-kerubina avatar Dec 14 '20 13:12 agnese-kerubina