If you haven't yet checkout out Netlify, you definitely should!
While Netlify has direct integration with Github, Bitbucket and the managed Gitlab service, things get confusing if you have your own Gitlab instance. This post is to help out anyone wanting to write a Gitlab pipeline to deploy their website directly to Netlify from Gitlab's CI/CD tool.
Head over to User Settings > Applications > Personal Access Token and generate a new access token. You put "Gitlab CD" as the description of your token. Once generated, make sure you copy and keep the access token in a file or in an active editor window.
Next, go to your site's setting page in Netlify Dashboard can copy the value of
Open the repo on your self-hosted Gitlab instance and go to Settings > CI/CD.
- Add the access token from step 1 under the variable name
- Add the API ID from step 2 under the variable name
Add the Gitlab CI file to your repo. Following is a basic template to start you off:
stages: - deploy deploy: stage: deploy environment: name: production url: https://your.website.com only: - master script: - npm i # your build command - npm run build - npx netlify-cli deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod
This file contains the directory which needs to be pushed to Netlify (the directory where your project is built). It's usually named
[build] publish = "build"
That's it! Now just commit these changes and push to
master and see your website get deployed on Netlify :)