Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FIREBASE_TOKEN deprecated in CI/CD gitlab

I encountered a warning while deploying my web app, firebase tells me that the token is about to be deprecated and I recommend using google credentials.

cicd output

Do you have any advice on how to setup the gitlab pipeline to use google credentials? I have not found a guide on this. This is my script.

gitlab script

At the moment I have configured a gitlab environment variable containing the token and it works (with warning).

gitlab firebase token

I tried setting the GOOGLE_APPLICATION_CREDENTIALS environment variable in gitlab settings but I don't know the firebase command to use to deploy.

like image 588
Gaetano Silluzio Avatar asked Jun 27 '26 23:06

Gaetano Silluzio


2 Answers

I found the way to deploy from gitlab using the GOOGLE_APPLICATION_CREDENTIALS. This is my script:

image: node:14.18.0-alpine

before_script:
  - npm i -g firebase-tools
  - echo $FIARD_PRIVATE_KEY > "/private-key.json"
  - export GOOGLE_APPLICATION_CREDENTIALS="/private-key.json"

stages:
  - staging
  - production

deploy_staging:
  stage: staging
  when: manual
  script:
    - firebase use staging
    - firebase deploy --only hosting:ineffe-business-site-staging
    - echo "Deploying hosting staging finished!"
  only:
    - master
  environment:
    name: staging
    url: https://staging-business-ineffe.firebaseapp.com/

deploy_production:
  stage: production
  when: manual
  script:
    - firebase use default
    - firebase deploy --only hosting:ineffe-business-site-prod
    - echo "Deploying hosting production finished!"
  only:
    - master
  environment:
    name: production
    url: https://business-ineffe-com.firebaseapp.com/

I created the environment variable on gitlab based on the environment (staging and production) and it works. The variables contain the authentication json provided by Google.

gitlab env variables

I posted this answer if it can be useful to someone.

like image 77
Gaetano Silluzio Avatar answered Jun 29 '26 15:06

Gaetano Silluzio


You can do that by printing the environment variable in a temporary json file and then use the file reference as GOOGLE_APPLICATION_CREDENTIALS. Although, the file gets deleted after build job completes, it's a good practice to clean the file after job ends explicitly.

image: node:20.12.2-buster # Use the latest LTS release of Node.js

stages: # List of stages for jobs, and their order of execution. Lets keep it simple for now
  - build-n-deploy

before_script:
  - npm i -g firebase-tools
  - firebase experiments:enable webframeworks # Enable the webframeworks experiment
  - echo $GOOGLE_APP_CRED > "$HOME/gccred.json"
  - export GOOGLE_APPLICATION_CREDENTIALS="$HOME/gccred.json"

after_script:
  - rm -rf $HOME/gccred.json

deploy-job: # This job runs in the deploy stage.
  stage: build-n-deploy
  environment: production
  script:
    - echo "Building My Awesome Blog"
    - npm install
    - echo "Deploying to Firebase"
    - firebase deploy
  only:
    refs:
      - main

Read more on CI/CD setup in Gitlab for Firebase Hosting & challenges faced

like image 20
Abhilash Nayak Avatar answered Jun 29 '26 14:06

Abhilash Nayak