GITLAB Continuous integration and delivery to firebase

Preetham Umarani
2 min readSep 22, 2021

Below is a simple example of GITLAB CI/CD pipeline.

Step1: Create a file in the root folder of your project with name

“.gitlab-ci.yml”

image: node:12.13.0-alpine

default:
before_script:
- npm i -g firebase-tools

stages:
- deploy

deploy_testbed:
stage: deploy
tags:
- bot-platform
- aws
script:
- cp .env-testbed .env.production
- echo "copying env"
- yarn
- echo "yarned"
- CI='' yarn run build
- echo "yarn build done"
- firebase use catalogue-testbed --token $FIREBASE_TOKEN_TESTBED
- firebase deploy --only hosting --token $FIREBASE_TOKEN_TESTBED
only:
refs:
- testbed

deploy_development:
stage: deploy
tags:
- bot-platform
- aws
script:
- cp .env-dev .env.production
- echo "copying env"
- yarn
- echo "yarned"
- CI='' yarn run build
- echo "yarn build done"
- firebase use dev-catalogue --token $FIREBASE_TOKEN_DEV
- firebase deploy --only hosting --token $FIREBASE_TOKEN_DEV
only:
refs:
- development

deploy_staging:
stage: deploy
tags:
- bot-platform
- aws
script:
- cp .env-qa .env.production
- echo "copying env"
- yarn
- echo "yarned"
- CI='' yarn run build
- echo "yarn build done"
- firebase use catalogue-qa --token $FIREBASE_TOKEN_QA
- firebase deploy --only hosting --token $FIREBASE_TOKEN_QA
only:
refs:
- staging

deploy_production:
stage: deploy
tags:
- bot-platform
- aws
script:
- cp .env-prod .env.production
- echo "copying env"
- yarn
- echo "yarned"
- CI='' yarn run build
- echo "yarn build done"
- firebase use catalogue-production --token $FIREBASE_TOKEN_PROD
- firebase deploy --only hosting --token $FIREBASE_TOKEN_PROD
only:
refs:
- main

very simple example of GITLAB CI script.

before script does the setup work for the docker environment.

stages of deployment like build, test and deploy. Here am using deploy directly.

you can see deploy_testbed, deploy_dev, deploy_staging, deploy_production as 4 snippets, all do basically same stuff with reference to different branches and deploy to different projects. Only: refs — main, is the trigger point for CI script whenever any change is pushed to main branch and do the deploy_production snippet.

So I think this is the simplest of all. Please refer to it and let me know if any queries.

Refer to this story for firebase CI/CD.

https://preethamumarani.medium.com/ci-cd-to-firebase-hosting-and-github-actions-c5535b79c8cc

Until Next Time! BBYE!

--

--