Recently I just made the move to Gitlab, for its powerful support of CI/CD (Continuous Integration / Continuous Delivery).
My blog (this site), which is powered by Gatsby is hosted there, and I wanna make use of the CI/CD pipeline. Here how it’s done.
To get started with Gitlab CI/CD, create a file name
.gitlab-ci.yml. This is the content:
image: node:latest cache: paths: - node_modules/ stages: - build build: script: - npm install - ./node_modules/.bin/gatsby build - npm i netlify-cli -g - netlify deploy --site=$NETLIFY_SITE_ID --auth=$NETLIFY_AUTH_TOKEN --prod artifacts: paths: - public only: - staging
image: node:lastest- Pull a node Docker image with tag
latest. We need
nodeenvironment for our npm install
cache- Gitlab CI leverages caching for improving pipeline speed for subsequent build. This case, the
node_modulewill be cached for every later build.
stage: There are 1 stage only for this pipeline
script: What you actually make the pipeline do. We leverage the
netlify-clito programmtically deploy our
$NETLIFY_AUTH_TOKEN are your secret Netlify credentials.
You can find these here:
- Netlify Site ID:
- Netlify Auth Token:
Then go to your gitlab repository, go to `Settings\CI/CD\Environment Variables and set them
That’s it. Please let me know if the script works.